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

View all the Fabric Data Days sessions on demand. View schedule

Reply
lilynguyen
Frequent Visitor

How to calculate the occurrence of top N in a measure.

I have a data like this

DeptCount of billDate
A501/1/2020
B2501/1/2020
C151/1/2020
D301/1/2020
E401/1/2020
A202/2/2020
B152/2/2020
C242/2/2020
D902/2/2020
E112/2/2020


So, I will create a measure to rank the Dept by column Count of bill by Date, I have the data like this:

DeptCount of billDateRank
A501/1/20204
B2501/1/20205
C151/1/20201
D301/1/20202
E401/1/20203
A202/2/20203
B152/2/20202
C242/2/20204
D902/2/20205
E112/2/20201

 

Now, I would like to have the frequency of Debt which in top 3 by date, like this:

DEPTOccurrence
A1
B1
C1
D1
E2

 

Any ideas from you guys?
Thanks so much

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression in a table visual with your Dept column, replacing Bills and Rank Measure with the actual names.

 

Occurrence =
VAR vThisDept =
    MIN ( Bills[Dept] )
VAR vSummary =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                Bills,
                Bills[Dept],
                Bills[Date]
            ),
            "cRank", [Rank Measure]
        ),
        ALLSELECTED ( Bills )
    )
RETURN
    COUNTROWS (
        FILTER (
            FILTER (
                vSummary,
                Bills[Dept] = vThisDept
            ),
            [cRank] <= 3
        )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
lilynguyen
Frequent Visitor

Tks so much for both of you guys. Both solutions works

sanalytics
Super User
Super User

@lilynguyen 

 

Also you can follow below pattern

 

sanalytics_0-1607178446742.png

 

attached is the pbix file

https://dropfiles.org/lBqAHOqz

 

Regards,

sanalytics

if it is your solution please like and accept it as your solution

mahoneypat
Microsoft Employee
Microsoft Employee

Please try this measure expression in a table visual with your Dept column, replacing Bills and Rank Measure with the actual names.

 

Occurrence =
VAR vThisDept =
    MIN ( Bills[Dept] )
VAR vSummary =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE (
                Bills,
                Bills[Dept],
                Bills[Date]
            ),
            "cRank", [Rank Measure]
        ),
        ALLSELECTED ( Bills )
    )
RETURN
    COUNTROWS (
        FILTER (
            FILTER (
                vSummary,
                Bills[Dept] = vThisDept
            ),
            [cRank] <= 3
        )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors