Pendiente anual
¿Qué categorías crecieron frente al año anterior, y cuánto?
Captura en Power BI Desktop sobre el modelo Contoso-Retail, año 2024.
Cada categoría del año anterior al año elegido en una escala común: verde si sube, roja si baja, con el importe de cada año y una píldora con flecha y porcentaje. El subtítulo cuenta cuántas crecen.
Qué necesita
- Una columna de categoría
- Una medida de ventas y otra del año anterior
- Un año filtrado
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 Sales] y [Sales PY] por tus medidas del año y del año anterior.
- 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.
pendiente-anual.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 Pendiente Anual =
-- Slope chart: each category from the prior year to the selected year, shared scale, colour + arrow by direction
VAR _yr = SELECTEDVALUE ( 'DimDate'[Year] )
VAR _t = ADDCOLUMNS ( VALUES ( 'DimProduct'[CategoryName] ), "@c", [Total Sales], "@p", [Sales PY] )
VAR _hi = MAXX ( _t, MAX ( [@c], [@p] ) )
VAR _lo = MINX ( _t, MIN ( [@c], [@p] ) )
VAR _up = COUNTROWS ( FILTER ( _t, [@c] >= [@p] ) )
VAR _rows =
CONCATENATEX (
_t,
VAR _y1 = 560 - DIVIDE ( [@p] - _lo, _hi - _lo ) * 380
VAR _y2 = 560 - DIVIDE ( [@c] - _lo, _hi - _lo ) * 380
VAR _d = DIVIDE ( [@c] - [@p], [@p] )
VAR _col = IF ( _d >= 0, "#1A7F37", "#C62F3E" )
VAR _bg = IF ( _d >= 0, "#E3F4E8", "#FBE5E8" )
VAR _nm = SUBSTITUTE ( 'DimProduct'[CategoryName], "&", "&" )
RETURN
"<line x1='420' y1='" & FORMAT ( _y1, "0.0", "en-US" ) & "' x2='780' y2='" & FORMAT ( _y2, "0.0", "en-US" ) & "' stroke='" & _col & "' stroke-width='5' stroke-linecap='round' opacity='0.9'/>"
& "<circle cx='420' cy='" & FORMAT ( _y1, "0.0", "en-US" ) & "' r='9' fill='#FFFFFF' stroke='#7395C0' stroke-width='4'/>"
& "<circle cx='780' cy='" & FORMAT ( _y2, "0.0", "en-US" ) & "' r='10' fill='" & _col & "' stroke='#FFFFFF' stroke-width='3'/>"
& "<text x='396' y='" & FORMAT ( _y1 + 6, "0.0", "en-US" ) & "' text-anchor='end' font-size='17'><tspan font-weight='600' fill='#1F2937'>" & _nm & "</tspan><tspan dx='10' font-size='14' fill='#6B7A90'>$" & FORMAT ( [@p] / 1e6, "0.00", "en-US" ) & "M</tspan></text>"
& "<text x='804' y='" & FORMAT ( _y2 + 6, "0.0", "en-US" ) & "' font-size='17' font-weight='600' fill='#1F3A5F'>$" & FORMAT ( [@c] / 1e6, "0.00", "en-US" ) & "M</text>"
& "<rect x='896' y='" & FORMAT ( _y2 - 13, "0.0", "en-US" ) & "' width='86' height='26' rx='13' fill='" & _bg & "'/>"
& "<text x='939' y='" & FORMAT ( _y2 + 5, "0.0", "en-US" ) & "' text-anchor='middle' font-size='14' font-weight='700' fill='" & _col & "'>" & IF ( _d >= 0, "▲ ", "▼ " ) & FORMAT ( ABS ( _d ), "0.0%", "en-US" ) & "</text>",
""
)
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'>"
& "<text x='48' y='48' font-size='26' font-weight='600' fill='#1F3A5F'>Ventas por categoría, " & ( _yr - 1 ) & " → " & _yr & "</text>"
& "<text x='48' y='80' font-size='16' fill='#6B7A90'>" & _up & " de " & COUNTROWS ( _t ) & " categorías crecen · misma escala para todas</text>"
& "<line x1='420' y1='150' x2='420' y2='590' stroke='#E3E8EF' stroke-width='2'/><line x1='780' y1='150' x2='780' y2='590' stroke='#E3E8EF' stroke-width='2'/>"
& "<text x='420' y='136' text-anchor='middle' font-size='18' font-weight='600' fill='#7395C0'>" & ( _yr - 1 ) & "</text>"
& "<text x='780' y='136' text-anchor='middle' font-size='18' font-weight='700' fill='#1F3A5F'>" & _yr & "</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.