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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Counts of Pivoted Data (as a column)

Hi!

 

I've been reading through other solutions and nothing seems to work. I am trying to create a column that will return counts of a specfic column/value after I've pivoted the data. A simplifed data sample is below:

 

 

1.PNG

 

 

 

I want to return a column that returns the ranking of each attribute based on the count of values. For example, if we look at the attribute "App", the value of "A" appears in 2 out of 3 instances. It would therefore be ranked 1 because it has the highest number of occurrences. I would prefer that the solution is a column rather than a measure, since I will be using the ranking as a slicer.

 

PS - the solution doesn't have to use a switch statement, that was just a thought…

 

Thank you!

 

 

 

 

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

There are two ways you could achieve that.

1. You need to create two calculated columns like below.

Column = CALCULATE(COUNT('Table'[value]),ALLEXCEPT('Table','Table'[Attribute],'Table'[value]))

rank = RANKX ( FILTER ( 'Table', 'Table'[Attribute] = EARLIER ( 'Table'[Attribute] ) ), 'Table'[Column], , DESC, DENSE )

2. You could just create one calculated column with the dax below.

rank_ =
VAR t =
    SUMMARIZE (
        FILTER ( 'Table', [Attribute] = EARLIER ( 'Table'[Attribute] ) ),
        [Attribute],
        'Table'[value],
        "C", COUNT ( 'Table'[value] )
    )
VAR t2 =
    ADDCOLUMNS (
        t,
        "Rank", RANKX ( FILTER ( t, [Attribute] = EARLIER ( 'Table'[Attribute] ) ), [C],, DESC )
    )
RETURN
    MAXX (
        FILTER (
            t2,
            [Attribute] = EARLIER ( [Attribute] )
                && [value] = EARLIER ( 'Table'[value] )
        ),
        [Rank]
    )

Here is the output.

Capture.PNG

Hope this can help you!

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you so much! Extremely helpful!

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous ,

There are two ways you could achieve that.

1. You need to create two calculated columns like below.

Column = CALCULATE(COUNT('Table'[value]),ALLEXCEPT('Table','Table'[Attribute],'Table'[value]))

rank = RANKX ( FILTER ( 'Table', 'Table'[Attribute] = EARLIER ( 'Table'[Attribute] ) ), 'Table'[Column], , DESC, DENSE )

2. You could just create one calculated column with the dax below.

rank_ =
VAR t =
    SUMMARIZE (
        FILTER ( 'Table', [Attribute] = EARLIER ( 'Table'[Attribute] ) ),
        [Attribute],
        'Table'[value],
        "C", COUNT ( 'Table'[value] )
    )
VAR t2 =
    ADDCOLUMNS (
        t,
        "Rank", RANKX ( FILTER ( t, [Attribute] = EARLIER ( 'Table'[Attribute] ) ), [C],, DESC )
    )
RETURN
    MAXX (
        FILTER (
            t2,
            [Attribute] = EARLIER ( [Attribute] )
                && [value] = EARLIER ( 'Table'[value] )
        ),
        [Rank]
    )

Here is the output.

Capture.PNG

Hope this can help you!

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.