- Inicio
- Recursos
- Galería HTML
- Ticket del cliente medio
Ticket del cliente medio
¿Cómo es el año de un cliente típico?
Grabación en Power BI Desktop sobre el modelo Contoso-Retail, año 2024.
El año del cliente medio impreso como un ticket de caja: lo que gasta en cada categoría a precio de lista, los descuentos y el total, con los pedidos y el gasto por pedido. Al margen, tres notas: la línea que más pesa, la categoría que más se repite y lo ahorrado con descuentos.
¿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 columna de categoría
- Medidas de clientes, ventas a precio de lista, pedidos, unidades, descuento y ventas por cliente
Cómo lo conecto a mis datos
- Copia la medida «HTML Average Customer Receipt» del archivo .dax.
- Cambia la columna de categoría y tus medidas de clientes, ventas a precio de lista, pedidos, unidades, descuento y ventas por cliente.
- Ponla en un visual HTML Content 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: put this measure in an HTML Content visual. Uses [Distinct Customers], [Gross Sales], [Orders], [Total Quantity], [Discount Amount], [Sales per Customer] and DimProduct[CategoryName] of Contoso-Retail.
-- By CSalcedoDataBI · https://csalcedodatabi.com/recursos/html-content-power-bi/ticket-cliente-medio · MIT
'HTML Average Customer Receipt' =
VAR _cust = [Distinct Customers]
VAR _lines =
FILTER (
ADDCOLUMNS (
VALUES ( 'DimProduct'[CategoryName] ),
"@g", DIVIDE ( [Gross Sales], _cust ),
"@o", DIVIDE ( [Orders], _cust ),
"@u", DIVIDE ( [Total Quantity], _cust ),
"@n", SUBSTITUTE ( SUBSTITUTE ( 'DimProduct'[CategoryName] & "", "&", "&" ), "<", "<" )
),
[@g] > 0
)
VAR _gross = DIVIDE ( [Gross Sales], _cust )
VAR _disc = DIVIDE ( [Discount Amount], _cust )
VAR _net = [Sales per Customer]
VAR _orders = DIVIDE ( [Orders], _cust )
VAR _top = TOPN ( 1, _lines, [@g], DESC )
VAR _year = SELECTEDVALUE ( 'DimDate'[Year] )
VAR _maxg = MAXX ( _lines, [@g] )
VAR _freq = TOPN ( 1, _lines, [@o], DESC )
RETURN
"<div style=""font-family:'Segoe UI',sans-serif;color:#334155;width:100%;height:100%;display:flex;flex-direction:column;box-sizing:border-box;padding:4px""> "
& "<div style=""font-size:16px;font-weight:700;color:#1F3A5F;margin:0 0 2px 2px"">The average customer's receipt" & IF ( ISBLANK ( _year ), "", " · " & _year ) & "</div> "
& "<div style=""font-size:12px;color:#64748B;margin:0 0 10px 2px"">One customer spends " & FORMAT ( _net, "$#,0", "en-US" ) & " in " & FORMAT ( _orders, "0.0", "en-US" ) & " orders · " & MAXX ( _top, [@n] ) & " takes " & FORMAT ( DIVIDE ( MAXX ( _top, [@g] ), _gross ), "0%", "en-US" ) & " of the bill · discounts save " & FORMAT ( DIVIDE ( _disc, _gross ), "0.0%", "en-US" ) & "</div> "
& "<div style=""flex:1;display:flex;justify-content:center;align-items:flex-start;gap:28px;background:#F1F5F9;border-radius:10px;padding:8px 10px""> "
& "<div style=""width:330px;background:#FFFFFF;font-family:Consolas,'Courier New',monospace;font-size:12px;color:#1E293B;padding:10px 16px 18px;box-shadow:0 2px 8px rgba(15,23,42,.18);border-radius:3px 3px 0 0;background-image:linear-gradient(135deg,#F1F5F9 25%,transparent 25%),linear-gradient(225deg,#F1F5F9 25%,transparent 25%);background-size:12px 12px;background-repeat:repeat-x;background-position:left bottom""> "
& "<div style=""text-align:center;font-weight:700;font-size:15px;letter-spacing:.15em"">CONTOSO STORES</div> "
& "<div style=""text-align:center;font-size:11px;color:#64748B"">average of " & FORMAT ( _cust, "#,0", "en-US" ) & " customers" & IF ( ISBLANK ( _year ), "", " · " & _year ) & "</div> "
& "<div style=""border-top:1px dashed #94A3B8;margin:4px 0""></div> "
& CONCATENATEX (
_lines,
"<div title=""" & [@n] & ": " & FORMAT ( [@o], "0.00", "en-US" ) & " orders and " & FORMAT ( [@u], "0.0", "en-US" ) & " units per customer"" style=""margin:2px 0""> "
& "<div style=""display:flex;justify-content:space-between""><span style=""white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:210px"">" & UPPER ( [@n] ) & "</span><span>" & FORMAT ( [@g], "$#,0.00", "en-US" ) & "</span></div> "
& "<div style=""display:flex;justify-content:space-between;color:#64748B;font-size:11px""><span> " & FORMAT ( [@o], "0.0", "en-US" ) & " orders · " & FORMAT ( [@u], "0.0", "en-US" ) & " units</span><span style=""display:inline-block;height:6px;margin-top:5px;background:#9FB7D4;width:" & ROUND ( DIVIDE ( [@g], _maxg ) * 70, 0 ) & "px""></span></div> "
& "</div>",
"",
[@g], DESC
) & " "
& "<div style=""border-top:1px dashed #94A3B8;margin:5px 0 4px""></div> "
& "<div style=""display:flex;justify-content:space-between""><span>SUBTOTAL (list price)</span><span>" & FORMAT ( _gross, "$#,0.00", "en-US" ) & "</span></div> "
& "<div style=""display:flex;justify-content:space-between;color:#1E7A45""><span>DISCOUNTS</span><span>-" & FORMAT ( _disc, "$#,0.00", "en-US" ) & "</span></div> "
& "<div style=""border-top:2px solid #1E293B;margin:4px 0""></div> "
& "<div style=""display:flex;justify-content:space-between;font-weight:700;font-size:16px""><span>TOTAL</span><span>" & FORMAT ( _net, "$#,0.00", "en-US" ) & "</span></div> "
& "<div style=""display:flex;justify-content:space-between;color:#64748B;font-size:11px;margin-top:2px""><span>" & FORMAT ( _orders, "0.0", "en-US" ) & " orders · avg</span><span>" & FORMAT ( DIVIDE ( _net, _orders ), "$#,0.00", "en-US" ) & " each</span></div> "
& "<div style=""margin:8px auto 2px;height:20px;width:220px;background:repeating-linear-gradient(90deg,#1E293B 0 2px,transparent 2px 4px,#1E293B 4px 5px,transparent 5px 8px,#1E293B 8px 11px,transparent 11px 13px)""></div> "
& "<div style=""text-align:center;font-size:11px;color:#64748B"">THANK YOU FOR SHOPPING</div> "
& "</div> "
& "<div style=""width:240px;display:flex;flex-direction:column;gap:12px;padding-top:8px""> "
& "<div style=""background:#FFFFFF;border-radius:8px;padding:10px 12px;border-left:4px solid #1F3A5F""><div style=""font-size:11px;color:#64748B;text-transform:uppercase;letter-spacing:.06em"">Biggest line</div><div style=""font-size:15px;font-weight:700;color:#1F3A5F"">" & MAXX ( _top, [@n] ) & "</div><div style=""font-size:12px"">" & FORMAT ( MAXX ( _top, [@g] ), "$#,0", "en-US" ) & " a year in only " & FORMAT ( MAXX ( _top, [@o] ), "0.0", "en-US" ) & " orders</div></div> "
& "<div style=""background:#FFFFFF;border-radius:8px;padding:10px 12px;border-left:4px solid #E4572E""><div style=""font-size:11px;color:#64748B;text-transform:uppercase;letter-spacing:.06em"">Most frequent</div><div style=""font-size:15px;font-weight:700;color:#1F3A5F"">" & MAXX ( _freq, [@n] ) & "</div><div style=""font-size:12px"">" & FORMAT ( MAXX ( _freq, [@o] ), "0.0", "en-US" ) & " orders a year, " & FORMAT ( DIVIDE ( MAXX ( _freq, [@g] ), MAXX ( _freq, [@o] ) ), "$#,0", "en-US" ) & " each</div></div> "
& "<div style=""background:#FFFFFF;border-radius:8px;padding:10px 12px;border-left:4px solid #1E7A45""><div style=""font-size:11px;color:#64748B;text-transform:uppercase;letter-spacing:.06em"">Saved with discounts</div><div style=""font-size:15px;font-weight:700;color:#1E7A45"">" & FORMAT ( _disc, "$#,0", "en-US" ) & " a year</div><div style=""font-size:12px"">" & FORMAT ( DIVIDE ( _disc, _gross ), "0.0%", "en-US" ) & " off the list price</div></div> "
& "</div> "
& "</div> "
& "</div>"
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.