cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Syndicate_Admin
Administrator
Administrator

RankX para mostrar categoría y no clasificación

Hola.

Parece que no puedo encontrar una respuesta, una pregunta simple, ¿cómo mostraría la clasificación de la categoría durante un período seleccionado?

Ahora mismo, para el ejercicio lo tengo de la siguiente manera:

Ranking Fruits = RANKX(ALL(Master[FruitName]),[Suma valor],,DESC,Denso)

RangoNombre de la frutaValor de suma
1Manzana500
2Pera439
3Plátano350
4Naranjas299
5Kiwi100


Quiero poder mostrar el ranking en matriz con ranking en 1ª columna, el periodo de tiempo como columna y para cada periodo de tiempo se muestre la categoría y no el ranking. Algo así como lo siguiente. Gracias.

Rangoene-21feb-21mar-21
1ManzanaPlátanoPera
2PeraManzanaNaranjas
3PlátanoPeraKiwi
4NaranjasNaranjasManzana
5KiwiKiwiPlátano
1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

@Tevon713 De acuerdo, hice esto con una tabla de clasificaciones desconectada (solo 1 - 5 en una sola columna llamada Rango) y luego una tabla de "FruitsBasket". La medida es:

Fruit Rank = 
    VAR __Rank = MAX('Rankings'[Rank])
    VAR __Table = 
        SUMMARIZE(
            'FruitsBasket',
            [FruitName],
            "__Value",SUM([Value])
        )
    VAR __RankTable = 
        ADDCOLUMNS(
            __Table,
            "__Rank",RANKX(__Table,[__Value],,DESC)
        )
RETURN
    MAXX(FILTER(__RankTable,[__Rank] = __Rank),[FruitName])

Esta fue mi mesa FruitsBasket:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}})
in
    #"Changed Type"

Tabla de clasificación:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Rank = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}})
in
    #"Changed Type"

Greg_Deckler_0-1630538250425.png

View solution in original post

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Hola

No estoy seguro de cuánto puedo ayudar, pero me gustaría intentarlo. Comparte el enlace desde donde puedo descargar tu archivo PBI.

Syndicate_Admin
Administrator
Administrator

@Tevon713 De acuerdo, hice esto con una tabla de clasificaciones desconectada (solo 1 - 5 en una sola columna llamada Rango) y luego una tabla de "FruitsBasket". La medida es:

Fruit Rank = 
    VAR __Rank = MAX('Rankings'[Rank])
    VAR __Table = 
        SUMMARIZE(
            'FruitsBasket',
            [FruitName],
            "__Value",SUM([Value])
        )
    VAR __RankTable = 
        ADDCOLUMNS(
            __Table,
            "__Rank",RANKX(__Table,[__Value],,DESC)
        )
RETURN
    MAXX(FILTER(__RankTable,[__Rank] = __Rank),[FruitName])

Esta fue mi mesa FruitsBasket:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}})
in
    #"Changed Type"

Tabla de clasificación:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Rank = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}})
in
    #"Changed Type"

Greg_Deckler_0-1630538250425.png

@Greg_Deckler Muchas gracias, esto funcionará por el momento.

Recién iluminado por algún gurú de PQ el otro día, se me ocurrió un método detallado para calcular el rango en lugar de ordenar,

Rank = List.Count( List.PositionOf( list, value, Occurrence.All, each _>=value ) )

Solo por diversión, aquí hay una solución de PQ basada en su abundante FruitBasket. ¡Bien!

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "YYYYMM", each Date.ToText([Month], "MMM yyyy")),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"YYYYMM"}, {{"ar", each _, type table [FruitName=nullable text, Month=nullable date, Value=nullable number, YYYYMM=text]}}),
    #"Added Rank" = Table.TransformColumns(#"Grouped Rows", {"ar", (t) => Table.AddColumn(t, "Rank", (r) => List.Count(List.PositionOf(t[Value], r[Value], Occurrence.All, each _ >= r[Value])))}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Added Rank", "ar", {"FruitName", "Rank"}, {"FruitName", "Rank"}),
    #"Pivoted Column" = Table.Pivot(#"Expanded ar", List.Distinct(#"Expanded ar"[YYYYMM]), "YYYYMM", "FruitName")
in
    #"Pivoted Column"

Screenshot 2021-09-02 042905.png

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors