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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
GuestUser
Helper V
Helper V

dax query - count of max occurence

Hi,

We are using power bi with ssas tabular model (connect live) option

we have below data:
Department    Hour    TransactionCount      week
D1                 1-2 pm            10                         week1
D1                  2-3 pm           20                         week1
D1                  3-4 pm          15                           week1
D1                 4-5 pm            20                            week1


Report needed in below format

Department      Max_Tran_Count     count_occurence         hour

D1                                    20                        2                          2-3 pm

need dax query for count_occurence

Any suggestion please

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Perhaps:

 

count_occurence measure =
  VAR __Max = [Max_Tran_Count]
  VAr __Table =
    SUMMARIZE(
      'Table',
      [Department],
      [Hour],
      [week],
      "__TransactionCount",SUM([TransactionCount])
    )
RETURN
  COUNTROWS(FILTER(__Table,[__TransactionCount] = __Max))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

Perhaps:

 

count_occurence measure =
  VAR __Max = [Max_Tran_Count]
  VAr __Table =
    SUMMARIZE(
      'Table',
      [Department],
      [Hour],
      [week],
      "__TransactionCount",SUM([TransactionCount])
    )
RETURN
  COUNTROWS(FILTER(__Table,[__TransactionCount] = __Max))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler

Thanks a lot ..it worked
(Just replaced sum by max)

Can u also pls suggest ..how to get hour column...since it is of string type

Great!

Do you mean you want to convert your hour column to numeric?


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler

Yes..sort of
As I have mentioned in above post..the report format that is needed..
Need to dispalay the hour also which has max transaction count

Oh, just use LOOKUPVALUE or MAXX(FILTER(...)...) for that. https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler

I tried..but not able to get expected result Could you please help here in providing the formula

See attached PBIX:

 

count_occurence = 
    VAR __Max = MAXX(ALLSELECTED('Table'),'Table'[TransactionCount])
RETURN
    COUNTROWS(FILTER('Table',[TransactionCount] = __Max))

hour measure = 
    VAR __Max = MAXX(ALLSELECTED('Table'),'Table'[TransactionCount])
RETURN
    MINX(FILTER('Table',[TransactionCount] = __Max),[Hour])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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