- Inicio
- Recursos
- Galería HTML
- Efecto festivos
Efecto festivos
¿Los festivos venden más o menos que un día normal?
Grabación en Power BI Desktop sobre el modelo Contoso-Retail, año 2024.
Una hoja de calendario por cada festivo del año: sus ventas frente a la media de un día normal del mismo día de la semana. La cabecera sale en verde si vendió más y en rojo si vendió menos, y el subtítulo cuenta cuántos festivos superan a un día normal, el mejor y el peor. Un clic en una hoja filtra el resto de la página por ese día.
¿Te aviso cuando salga un visual nuevo?
Opcional: la descarga no lo necesita. Un correo cada dos semanas como mucho. Y si quieres todos los visuales de pago, está el Pase Deneb.
Qué necesita
- Una tabla de fechas con la fecha, el nombre del festivo y una marca de festivo (verdadero o falso)
- El número y el nombre del día de la semana
- Una medida de ventas
Cómo lo conecto a mis datos
- Copia del archivo .dax las medidas «HTML Holiday Effect» (el visual) y «Holiday Effect Summary» (la línea de lectura).
- Cambia tu medida de ventas y las columnas de tu tabla de fechas: fecha, nombre del festivo, marca de festivo y día de la semana.
- En un visual HTML Content pon la medida en Values y tu fecha en Context; activa Cross-filtering, pega la hoja de estilo del final del .dax en Stylesheet, usa «Holiday Effect Summary» como subtítulo y filtra un año en la página.
La medida completa
Es la misma que el archivo .dax de la carpeta. Cópiala con el botón.
-- The HTML: an HTML Content visual in row mode. Uses [Total Sales] and DimDate[Date], [HolidayName], [IsHoliday], [DayOfWeek], [DayName] of Contoso-Retail.
-- 1. Values: the measure 'HTML Holiday Effect'. Context: 'DimDate'[Date] (one visual row each; a click on one cross-filters the page).
-- 2. Format > Cross-filtering: on. Format > Stylesheet: paste the stylesheet at the end of this file.
-- 3. Title: the visual's own title; Subtitle: the measure 'Holiday Effect Summary' (fx), the reading line.
-- By CSalcedoDataBI · https://csalcedodatabi.com/recursos/html-content-power-bi/efecto-festivos · MIT
'HTML Holiday Effect' =
-- One visual row per date of the page's year; only the holidays draw a sheet, the other dates return BLANK and drop.
VAR _isHol = SELECTEDVALUE ( 'DimDate'[IsHoliday] ) = TRUE ()
VAR _date = SELECTEDVALUE ( 'DimDate'[Date] )
VAR _wd = SELECTEDVALUE ( 'DimDate'[DayOfWeek] )
VAR _day = SELECTEDVALUE ( 'DimDate'[DayName] ) & ""
VAR _name = SUBSTITUTE ( SUBSTITUTE ( SELECTEDVALUE ( 'DimDate'[HolidayName] ) & "", "&", "&" ), "<", "<" )
-- Baseline: the average sales of an ordinary (non-holiday) day of the same weekday in the year.
VAR _base =
CALCULATETABLE (
ADDCOLUMNS ( VALUES ( 'DimDate'[DayOfWeek] ), "@b", CALCULATE ( AVERAGEX ( VALUES ( 'DimDate'[Date] ), [Total Sales] ) ) ),
REMOVEFILTERS ( 'DimDate'[Date] ),
'DimDate'[IsHoliday] = FALSE ()
)
-- Every holiday of the year with its lift, to rank this one among them.
VAR _hols =
ADDCOLUMNS (
CALCULATETABLE (
SUMMARIZE ( 'DimDate', 'DimDate'[Date], 'DimDate'[DayOfWeek] ),
ALLSELECTED ( 'DimDate'[Date] ),
'DimDate'[IsHoliday] = TRUE ()
),
"@l",
VAR _w = 'DimDate'[DayOfWeek]
VAR _bw = MAXX ( FILTER ( _base, 'DimDate'[DayOfWeek] = _w ), [@b] )
RETURN ROUND ( DIVIDE ( CALCULATE ( [Total Sales] + 0 ) - _bw, _bw ), 2 )
)
VAR _v = [Total Sales] + 0
VAR _b = MAXX ( FILTER ( _base, 'DimDate'[DayOfWeek] = _wd ), [@b] )
VAR _l = ROUND ( DIVIDE ( _v - _b, _b ), 2 )
VAR _n = COUNTROWS ( _hols )
VAR _rank = COUNTROWS ( FILTER ( _hols, [@l] > _l ) ) + 1
VAR _tone = SWITCH ( TRUE (), _l > 0, "up", _l < 0, "down", "even" )
RETURN
IF (
NOT _isHol,
BLANK (),
"<div class=""hol-sheet " & _tone & """ title=""" & _name & ": " & FORMAT ( _v, "$#,0", "en-US" ) & " vs " & FORMAT ( _b, "$#,0", "en-US" ) & " on an ordinary " & _day & " · gap " & FORMAT ( _v - _b, "+$#,0;-$#,0", "en-US" ) & " · rank " & _rank & " of " & _n & " holidays by lift""> "
& "<div class=""hol-head"">" & UPPER ( FORMAT ( _date, "MMM yyyy", "en-US" ) ) & "</div> "
& "<div class=""hol-day""><span class=""hol-num"">" & DAY ( _date ) & "</span><span class=""hol-dow"">" & LEFT ( _day, 3 ) & "</span></div> "
& "<div class=""hol-name"">" & _name & "</div> "
& "<div class=""hol-foot""> "
& "<div class=""hol-vals""><span class=""hol-v"">" & FORMAT ( _v / 1000, "$#,0.0", "en-US" ) & "K</span><span class=""hol-l"">" & FORMAT ( _l, "▲ 0%;▼ 0%;= 0%", "en-US" ) & "</span></div> "
& "<div class=""hol-base"">vs " & FORMAT ( _b / 1000, "$#,0.0", "en-US" ) & "K on a normal " & _day & "</div> "
& "</div> "
& "</div>"
)
-- The reading line, for the visual's subtitle.
'Holiday Effect Summary' =
VAR _base =
CALCULATETABLE (
ADDCOLUMNS ( VALUES ( 'DimDate'[DayOfWeek] ), "@b", CALCULATE ( AVERAGEX ( VALUES ( 'DimDate'[Date] ), [Total Sales] ) ) ),
'DimDate'[IsHoliday] = FALSE ()
)
VAR _l =
ADDCOLUMNS (
CALCULATETABLE (
SUMMARIZE ( 'DimDate', 'DimDate'[Date], 'DimDate'[HolidayName], 'DimDate'[DayOfWeek] ),
'DimDate'[IsHoliday] = TRUE ()
),
"@l",
VAR _w = 'DimDate'[DayOfWeek]
VAR _bw = MAXX ( FILTER ( _base, 'DimDate'[DayOfWeek] = _w ), [@b] )
RETURN ROUND ( DIVIDE ( CALCULATE ( [Total Sales] + 0 ) - _bw, _bw ), 2 )
)
VAR _best = TOPN ( 1, _l, [@l], DESC )
VAR _worst = TOPN ( 1, _l, [@l], ASC )
RETURN
IF (
COUNTROWS ( _l ) > 0,
COUNTROWS ( FILTER ( _l, [@l] > 0 ) ) & " of " & COUNTROWS ( _l )
& " holidays sell above an ordinary day of the same weekday · best "
& MAXX ( _best, 'DimDate'[HolidayName] ) & " (" & FORMAT ( MAXX ( _best, [@l] ), "+0%;-0%", "en-US" ) & ") · worst "
& MAXX ( _worst, 'DimDate'[HolidayName] ) & " (" & FORMAT ( MAXX ( _worst, [@l] ), "+0%;-0%", "en-US" ) & ")"
)
/* Stylesheet (Format > Stylesheet):
#htmlContent { font-family: 'Segoe UI', sans-serif; color: #334155; display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: minmax(0, 1fr); gap: 10px; box-sizing: border-box; padding: 4px; height: 100%; overflow: hidden; }
.htmlViewerEntry { display: flex; min-width: 0; cursor: pointer; transition: opacity 120ms ease; }
.htmlViewerEntry > div { display: flex; flex: 1; min-width: 0; }
.htmlViewerEntry:empty { display: none; }
.htmlViewerEntry.unselected { opacity: 0.35; }
.hol-sheet { flex: 1; min-width: 0; border-radius: 8px; background: #FFFFFF; box-shadow: 0 1px 3px rgba(15, 23, 42, .18); overflow: hidden; display: flex; flex-direction: column; border: 1px solid #E2E8F0; }
.htmlViewerEntry:hover .hol-sheet { box-shadow: 0 3px 10px rgba(15, 23, 42, .28); border-color: #94A3B8; }
.hol-head { color: #FFFFFF; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-align: center; padding: 3px 0; background: #64748B; }
.hol-sheet.up .hol-head { background: #1E7A45; }
.hol-sheet.down .hol-head { background: #B42318; }
.hol-day { display: flex; align-items: baseline; justify-content: center; gap: 6px; padding: 4px 6px 0; }
.hol-num { font-size: 34px; font-weight: 800; color: #1F3A5F; line-height: 1; }
.hol-dow { font-size: 11px; color: #64748B; }
.hol-name { font-size: 11px; font-weight: 600; color: #334155; text-align: center; padding: 2px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hol-foot { margin: auto 8px 8px; border-top: 1px dashed #CBD5E1; padding-top: 5px; }
.hol-vals { display: flex; justify-content: space-between; align-items: baseline; }
.hol-v { font-size: 14px; font-weight: 700; color: #334155; }
.hol-l { font-size: 14px; font-weight: 700; color: #64748B; }
.hol-sheet.up .hol-l { color: #1E7A45; }
.hol-sheet.down .hol-l { color: #B42318; }
.hol-base { font-size: 10px; color: #64748B; }
*/ El informe lee los datos de muestra por internet: al abrirlo la primera vez, pulsa Actualizar. El visual responde a los filtros de la página. Licencia MIT.