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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
seba
Helper II
Helper II

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.