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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.