cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
manojsv19
Regular Visitor

DAX measure to show the max customers count and the corresponding date by grouping of date field

Hello All,

 

I have a requirement to create a DAX measure to calculate to show the max customers count by grouping them on date and to display the corresponding day with max customers count.  I am using directy query and not storing any data inside Power BI

 

Below is the dummied data table to illustrate my scenario.Here, i wanted to calcualate the sum of customers count by grouping them on Date column, then display the date with maxium customers count and also want to display the max customers count.

I have also provided the table after grouping by date. At the end, i wanted to display the max customers count (946) and the corresponding date (11/13/2019). 

 

I would appreciate any suggestions or feedback to get the max customers count and the corresponding date field using DAX measure in Direct Query.

 

Fact Table

 DateCustomers Count
11/1/2019230
11/1/2019150
11/1/2019245
11/2/2019165
11/2/2019176
11/2/2019185
11/13/201956
11/13/2019320
11/13/2019120
11/13/2019450
11/24/2019190
11/24/2019120
11/24/2019340
11/24/2019230

 

Table after grouping the data based on date field

 

DateCustomers Count
11/1/2019625
11/2/2019526
11/13/2019946
11/24/2019880

 

Thank you!!

2 ACCEPTED SOLUTIONS
Nathaniel_C
Super User
Super User

Hello @manojsv19 ,

Try this:date number.PNGFirst measure

Max Count of Customers on one day = 


VAR _newTable =
    ADDCOLUMNS (
        'Table',
        "Sum of customers per d", CALCULATE (
            SUM ( 'Table'[Customers Count] ),
            ALLEXCEPT ( 'Table', 'Table'[ Date] )
        )
    )
VAR _newTableMax =
    MAXX ( _newTable, [Sum of customers per d] )



RETURN
    _newTableMax

 Created a calculated column

Sum of customers per date = CALCULATE(sum('Table'[Customers Count]),ALLEXCEPT('Table','Table'[ Date]))

 Last measure

Date with highest count of customers = 
var _maxCount = MAX('Table'[Sum of customers per date])
return
CALCULATE(MAX('Table'[ Date]),FILTER(ALLEXCEPT('Table','Table'[ Date]),'Table'[Sum of customers per date]=_maxCount))

 
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




View solution in original post

Hi @manojsv19 ,

Figured out the syntax of a the virtual table so that you don't need to create a calculated column. This replaces the last measure.

Date with highest count of customers 2 = 
VAR _newTable =
    ADDCOLUMNS (
        'Table',
        "Sum of customers per d", CALCULATE (
            SUM ( 'Table'[Customers Count] ),
            ALLEXCEPT ( 'Table', 'Table'[ Date] )
        )
    )
VAR _newTableMax =
    MAXX ( _newTable, [Sum of customers per d] )

var _calc = CALCULATE(MAX('Table'[ Date]),FILTER(_newTable,MAX([Sum of customers per d] )= _newTableMax))

RETURN
    _calc


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
Nathaniel_C
Super User
Super User

Hello @manojsv19 ,

Try this:date number.PNGFirst measure

Max Count of Customers on one day = 


VAR _newTable =
    ADDCOLUMNS (
        'Table',
        "Sum of customers per d", CALCULATE (
            SUM ( 'Table'[Customers Count] ),
            ALLEXCEPT ( 'Table', 'Table'[ Date] )
        )
    )
VAR _newTableMax =
    MAXX ( _newTable, [Sum of customers per d] )



RETURN
    _newTableMax

 Created a calculated column

Sum of customers per date = CALCULATE(sum('Table'[Customers Count]),ALLEXCEPT('Table','Table'[ Date]))

 Last measure

Date with highest count of customers = 
var _maxCount = MAX('Table'[Sum of customers per date])
return
CALCULATE(MAX('Table'[ Date]),FILTER(ALLEXCEPT('Table','Table'[ Date]),'Table'[Sum of customers per date]=_maxCount))

 
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Hi @manojsv19 ,

Figured out the syntax of a the virtual table so that you don't need to create a calculated column. This replaces the last measure.

Date with highest count of customers 2 = 
VAR _newTable =
    ADDCOLUMNS (
        'Table',
        "Sum of customers per d", CALCULATE (
            SUM ( 'Table'[Customers Count] ),
            ALLEXCEPT ( 'Table', 'Table'[ Date] )
        )
    )
VAR _newTableMax =
    MAXX ( _newTable, [Sum of customers per d] )

var _calc = CALCULATE(MAX('Table'[ Date]),FILTER(_newTable,MAX([Sum of customers per d] )= _newTableMax))

RETURN
    _calc


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Helpful resources

Announcements
Join Arun Ulag at MPPC23

Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors