Pictograma de unidades
¿Qué categorías mueven más unidades, a simple vista?
Captura en Power BI Desktop sobre el modelo Contoso-Retail, año 2024.
Bolsas de compra proporcionales a las unidades vendidas por categoría: cada bolsa vale lo mismo y la última se corta a su fracción. Al lado, el total y la parte de las unidades.
Qué necesita
- Una columna de categoría
- Una medida de unidades
Cómo lo conecto a mis datos
- Copia la medida de abajo y crea una medida nueva con ella.
- Cambia 'DimProduct'[CategoryName] por tu columna y [Total Quantity] por tu medida de unidades.
- Pon su categoría de datos en «URL de imagen» (Herramientas de medidas → Categoría de datos).
- Añade un visual Imagen → Formato → Imagen → «Seleccionar desde datos» → la medida, 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.
pictograma-unidades.dax
-- SVG measure for Power BI: set its data category to Image URL and show it in an Image visual (Format > Image > Select from data).
-- Uses the Contoso-Retail master: DimProduct columns and [Total Sales], [Sales PY], [Total Quantity], [Margin %].
SVG Pictograma Unidades =
-- Pictogram: one shopping bag per 1/20 of the largest category, the last bag cut to its share
VAR _yr = SELECTEDVALUE ( 'DimDate'[Year] )
VAR _t = ADDCOLUMNS ( VALUES ( 'DimProduct'[CategoryName] ), "@v", [Total Quantity] )
VAR _r = ADDCOLUMNS ( _t, "@r", RANKX ( _t, [@v], , DESC, DENSE ) )
VAR _max = MAXX ( _t, [@v] )
VAR _unit = _max / 20
VAR _tot = [Total Quantity]
VAR _bag = "<path d='M5 14 H29 L27.5 34 Q27.3 36 25.3 36 H8.7 Q6.7 36 6.5 34 Z' stroke-width='1.5' stroke-linejoin='round'/><path d='M12 17 V10.5 a5 5 0 0 1 10 0 V17' fill='none' stroke-width='2.6' stroke-linecap='round'/>"
VAR _line = CONCATENATEX ( GENERATESERIES ( 0, 19 ), "<use href='#bag' x='" & [Value] * 38 & "'/>", "" )
VAR _rows =
CONCATENATEX (
_r,
VAR _y = 112 + ( [@r] - 1 ) * 128
VAR _w = DIVIDE ( [@v], _unit ) * 38
VAR _id = "c" & [@r]
RETURN
"<g transform='translate(48," & _y & ")'>"
& "<text x='0' y='20' font-size='18' font-weight='600' fill='#1F2937'>" & SUBSTITUTE ( 'DimProduct'[CategoryName], "&", "&" ) & "</text>"
& "<text x='0' y='42' font-size='14' fill='#6B7A90'>" & FORMAT ( DIVIDE ( [@v], _tot ), "0%", "en-US" ) & " de las unidades</text>"
& "<clipPath id='" & _id & "'><rect x='0' y='0' width='" & FORMAT ( _w, "0.0", "en-US" ) & "' height='44'/></clipPath>"
& "<g transform='translate(250,8)'>"
& "<g fill='#E6ECF3' stroke='#E6ECF3'>" & _line & "</g>"
& "<g fill='url(#gb)' stroke='#1F3A5F' clip-path='url(#" & _id & ")'>" & _line & "</g>"
& "</g>"
& "<text x='1104' y='36' text-anchor='end' font-size='22' font-weight='700' fill='#1F3A5F'>" & FORMAT ( [@v] / 1000, "0.0", "en-US" ) & " K</text>"
& "</g>",
"",
[@r], ASC
)
RETURN
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 650' width='1200' height='650' font-family='Segoe UI, sans-serif'>"
& "<defs><linearGradient id='gb' x1='0' x2='0' y1='0' y2='1'><stop offset='0' stop-color='#2E6BA0'/><stop offset='1' stop-color='#1F3A5F'/></linearGradient><symbol id='bag' overflow='visible'>" & _bag & "</symbol></defs>"
& "<text x='48' y='48' font-size='26' font-weight='600' fill='#1F3A5F'>Unidades vendidas por categoría</text>"
& "<text x='48' y='80' font-size='16' fill='#6B7A90'>" & _yr & " · cada bolsa = " & FORMAT ( _unit / 1000, "0.0", "en-US" ) & " K unidades · " & FORMAT ( _tot / 1000, "0.0", "en-US" ) & " K en total</text>"
& _rows
& "</svg>" 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.