Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Sayri
Helper I
Helper I

TOP N Matrix y expandir todo hacia abajo en la jerarquía

Querida comunidad,

Busqué en el foro y probé múltiples soluciones, pero ninguna de ellas está funcionando en mi caso.
Desafortunadamente por razones de confidencialidad, no puedo compartir una muestra de los datos
Pero estoy tratando de hacer eso:
en una Matrix que tiene un Top 3 por nivel y mantener el top 3 cada vez que estoy expandiendo todo hacia abajo en la jerarquía
2020-12-30 13-22-46.png

Gracias al foro ya he encontrado y probado los dos siguientes enlaces sin éxito:
https://dataninjago.com/2017/12/11/dax-ranking-with-hierarchy-drill-down/
https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/
He intentado diferentes maneras, con TOPN o RANKX, pero cada vez el primer nivel está clasificando, pero los 2 siguientes niveles no lo son.
¿Algún consejo / ideas por favor?

5 REPLIES 5
amitchandak
Super User
Super User

CNENFRNL
Community Champion
Community Champion

Hola, @Sayri, ya que estás destinado a extraer el top 3 en cada nivel, necesitas calcular rangos en cada nivel respectivamente. es posible que desee utilizar un patrón de este tipo,

Top3 =
VAR __rank =
    SWITCH (
        TRUE (),
        ISINSCOPE ( Category[Lvl3] ), RANKX ( ALL ( Category[Lvl3] ), [Total Sales] ),
        ISINSCOPE ( Category[Lvl2] ), RANKX ( ALL ( Category[Lvl2] ), [Total Sales] ),
        ISINSCOPE ( Category[Lvl1] ), RANKX ( ALL ( Category[Lvl1] ), [Total Sales] )
    )
RETURN
    IF ( __rank <= 3, [Total Sales] )

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Gracias @CNENFRNL
y Feliz Año Nuevo !!
en realidad funciona perfectamente para las 2 primeras categorías,
2021-01-04 08-52-25.png
para el 3d tuve que añadir algunas condiciones como abajo, y está casi funcionando, excepto...

Top3 = 
VAR __rank =
    SWITCH (
        TRUE (),
        ISINSCOPE ('Case'[Lvl1]) && ISINSCOPE('Case'[Lvl12] ) && ISINSCOPE ('Case'[Lvl13] ), RANKX ( ALLSELECTED ( 'Case'[Lvl13] ), [Total Sales] ),
        ISINSCOPE ('Case'[Lvl1]) && ISINSCOPE('Case'[Lvl12]) && NOT ISINSCOPE ('Case'[Lvl13]), RANKX ( ALLSELECTED ( 'Case'[Lvl12] ), [Total Sales] ),
        ISINSCOPE ('Case'[Lvl1]) && NOT ISINSCOPE('Case'[Lvl12]) && NOT ISINSCOPE ('Case'[Lvl13]), RANKX ( ALLSELECTED ( 'Case'[Lvl13] ), [Total Sales] )
        
    )
RETURN
    IF ( __rank <= 3, [Total Sales])

Incluso vacío, todavía está mostrando el categ anterior (ver la captura de pantalla a continuación)
Traté de añadir 'BLANK ()' a la condición IF,
'RETURN
IF ( __rank <-3, [Total de Ventas], BLANK() )'
pero no tiene ningún efecto en lo que me gustaría ocultar
¿Algún consejo, idea por favor?
2021-01-04 08-55-50.png
'RETURN
IF ( __rank <-3, [Total de Ventas], BLANK() )'

amitchandak
Super User
Super User

@Sayri , Trate de crear un meausre de rango como este y filtrar Rango <

rankx(filter(allselected(Table[category], Table[SubCateg]), Table[category] ?max(Table[category])), [sales value],,desc,dense)

Para rango Consulte estos enlaces
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Gracias @amitchandak
En realidad, lo que propones está funcionando bien para el segundo nivel de la jerarquía, pero no para el nivel superior 😕 (todo el rango permanece 1 allí)
Y hay 3 niveles de jerarquía en la matriz
¿Puede tener alguna otra idea?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.