Puntuación

Estrellas de valoración

¿Qué subcategorías dejan mejor margen, puntuadas de ½ a 5 estrellas?

Valoración por margen de Contoso 2024: Video Games 5 estrellas con 38,3 % de margen; Video Game Consoles media estrella con −4,2 %.

Captura en Power BI Desktop sobre el modelo Contoso-Retail, año 2024.

Cada subcategoría recibe de ½ a 5 estrellas según su margen, en tarjetas a dos columnas ordenadas de mejor a peor, con medias estrellas limpias, la nota y el margen real.

Qué necesita

  • Una columna de subcategoría
  • Una medida que puntuar (aquí, margen %)

Cómo lo conecto a mis datos

  1. Copia la medida de abajo y crea una medida nueva con ella.
  2. Cambia 'DimProduct'[SubCategoryName] por tu columna y [Margin %] por la medida que puntúa: la mejor recibe 5 estrellas y la peor ½.
  3. Pon su categoría de datos en «URL de imagen» (Herramientas de medidas → Categoría de datos).
  4. 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.

estrellas-valoracion.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 Estrellas Valoracion =
-- Stars from 0.5 to 5 by the rank of Margin % among the visible subcategories; half stars cut smoothly
VAR _yr = SELECTEDVALUE ( 'DimDate'[Year] )
VAR _t = ADDCOLUMNS ( VALUES ( 'DimProduct'[SubCategoryName] ), "@m", [Margin %] )
VAR _n = COUNTROWS ( _t )
VAR _r =
    ADDCOLUMNS (
        _t,
        "@pos", RANKX ( _t, [@m], , DESC, DENSE ),
        "@s", IF ( _n <= 1, 5, MAX ( 0.5, ROUND ( DIVIDE ( RANKX ( _t, [@m], , ASC, DENSE ) - 1, _n - 1 ) * 9, 0 ) / 2 + 0.5 ) )
    )
VAR _star = "<path d='M14 2.5 L17.4 9.4 L25 10.5 L19.5 15.8 L20.8 23.4 L14 19.8 L7.2 23.4 L8.5 15.8 L3 10.5 L10.6 9.4 Z' stroke-width='2.2' stroke-linejoin='round'/>"
VAR _five = CONCATENATEX ( GENERATESERIES ( 0, 4 ), "<use href='#st' x='" & [Value] * 32 & "'/>", "" )
VAR _half = CEILING ( _n / 2, 1 )
VAR _rows =
    CONCATENATEX (
        _r,
        VAR _col = IF ( [@pos] <= _half, 0, 1 )
        VAR _i = IF ( _col = 0, [@pos], [@pos] - _half ) - 1
        VAR _x = 48 + _col * 572
        VAR _y = 116 + _i * 74
        VAR _w = INT ( [@s] ) * 32 + IF ( MOD ( [@s], 1 ) > 0, 14, 0 )
        VAR _id = "s" & [@pos]
        RETURN
            "<g transform='translate(" & _x & "," & _y & ")'>"
                & "<rect x='0.5' y='0.5' width='539' height='61' rx='14' fill='#FFFFFF' stroke='#DDE4EE'/>"
                & "<text x='20' y='27' font-size='16' font-weight='600' fill='#1F2937'>" & SUBSTITUTE ( 'DimProduct'[SubCategoryName], "&", "&amp;" ) & "</text>"
                & "<text x='20' y='48' font-size='13' fill='#6B7A90'>margen " & FORMAT ( [@m], "0.0%", "en-US" ) & "</text>"
                & "<clipPath id='" & _id & "'><rect x='0' y='0' width='" & _w & "' height='30'/></clipPath>"
                & "<g transform='translate(318,17)'>"
                & "<g fill='#E3E8EF' stroke='#E3E8EF'>" & _five & "</g>"
                & "<g fill='url(#gs)' stroke='#E8A317' clip-path='url(#" & _id & ")'>" & _five & "</g>"
                & "</g>"
                & "<text x='520' y='38' text-anchor='end' font-size='17' font-weight='700' fill='#1F3A5F'>" & FORMAT ( [@s], "0.0", "en-US" ) & "</text>"
                & "</g>",
        "",
        [@pos], 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='gs' x1='0' x2='0' y1='0' y2='1'><stop offset='0' stop-color='#FFCF5C'/><stop offset='1' stop-color='#F0A21B'/></linearGradient><symbol id='st' overflow='visible'>" & _star & "</symbol></defs>"
        & "<text x='48' y='48' font-size='26' font-weight='600' fill='#1F3A5F'>Valoración por margen de cada subcategoría</text>"
        & "<text x='48' y='80' font-size='16' fill='#6B7A90'>" & _yr & " · 5 estrellas = el mejor margen, ½ = el peor · ordenado de mejor a peor</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.

¡Contáctame!