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
seba
Helper I
Helper I

Count number of occurrences per month and rank them in unique manner

I have the below table. The task is to count number of occurrences of each category per each month and then present top ten (count wise) categories on the 100% stacked column chart. I am able to count occurrences , but then power bi sums them for selected period of time (multiple months for example). I tried to rank them, but if number of occurrences is same, then the same rank is assigned and this leads to incorrect data as numbers are added again. Your help is greatly appreaciated. Using powerBi desktop with report server.

 

ItemCreated MonthCategoryAssigne
Item AJan-20XF
Item BFeb-20YE
Item CJan-20ZD
Item AApr-20XD
Item BJan-20YD
Item CFeb-20ZE
Item AMar-20ZF
Item BJan-20ZF
Item CMar-20YF
1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi @seba 

 

can you give this a go:

number of occurences =
CALCULATE (
    COUNT ( 'Table'[Item] ),
    FILTER (
        VALUES ( 'Table'[Category] ),
        RANKX (
            ALL ( 'Table'[Category] ),
            CALCULATE ( COUNT ( 'Table'[Item] ) )
                + INT ( CALCULATE ( UNICODE ( MIN ( 'Table'[Category] ) ) ) ) / 100000,
            ,
            DESC
        ) <= 10
    )
)

 

The 

+ INT ( CALCULATE ( UNICODE ( MIN ( 'Table'[Category] ) ) ) ) / 100000

-part is for breaking any ties

Cheers,
Sturla

View solution in original post

2 REPLIES 2
sturlaws
Resident Rockstar
Resident Rockstar

Hi @seba 

 

can you give this a go:

number of occurences =
CALCULATE (
    COUNT ( 'Table'[Item] ),
    FILTER (
        VALUES ( 'Table'[Category] ),
        RANKX (
            ALL ( 'Table'[Category] ),
            CALCULATE ( COUNT ( 'Table'[Item] ) )
                + INT ( CALCULATE ( UNICODE ( MIN ( 'Table'[Category] ) ) ) ) / 100000,
            ,
            DESC
        ) <= 10
    )
)

 

The 

+ INT ( CALCULATE ( UNICODE ( MIN ( 'Table'[Category] ) ) ) ) / 100000

-part is for breaking any ties

Cheers,
Sturla

Wow, that is amazing and impressive! It does work! Thank you very much! 

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.