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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors