cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

Accepted Solutions
Highlighted
Super User IX
Super User IX

Re: dax query - count of max occurence

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))

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
Highlighted
Super User IX
Super User IX

Re: dax query - count of max occurence

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))

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Highlighted
Helper V
Helper V

Re: dax query - count of max occurence

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
Highlighted
Super User IX
Super User IX

Re: dax query - count of max occurence

Great!

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

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Helper V
Helper V

Re: dax query - count of max occurence

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
Highlighted
Super User IX
Super User IX

Re: dax query - count of max occurence

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


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Helper V
Helper V

Re: dax query - count of max occurence

Hi @Greg_Deckler

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

Re: dax query - count of max occurence

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])

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Meet the 2020 Season 2 Power BI Super Users!

Meet the 2020 Season 2 Power BI Super Users!

Find out who's part of the program this season, and welcome the new Super Users.

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

July 2020 Community Highlights

July 2020 Community Highlights

Learn about the exciting things that happened in July.

Featured Data Story of The Month

Featured Data Story of The Month

All Data Stories Gallery contributions are reviewed for each month. We select a contribution and feature the community member the following month.

Power BI Dev Camp - Developing with .NET Core

Power BI Dev Camp - Developing with .NET Core

Learn how to develop custom web applications for Power BI using .NET Core 3.1 and .NET 5.

Top Solution Authors
Top Kudoed Authors