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
Anonymous
Not applicable

Max of a measure for each ID

Hi,

 

I have a sales table as follows :

Customer IDDateSaleMeasure 1Measure 2
110/01/20224001
115/02/20225011
112/05/20226011
215/10/20222001
214/11/20223411
315/03/20222300

I have created a measure 1 which detects if the customer is a returning customer and thus returns either 0 or 1.

Now I need to create another measure (Measure 2) which gets the max value for every customer as shown in the table above. 

 

I've tried DAX below, but it doesn't work right.

Measure 2 = MAXX(CALCULATETABLE(VALUES('Sales[CustomerID]), ALLSELECTED('Sales'[CustomerID])), [Measure 1])
It returns 
Customer IDDateSaleMeasure 1Measure 2
110/01/20224000
115/02/20225011
112/05/20226011
215/10/20222000
214/11/20223411
315/03/20222300
 
Please help!
 
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

I think you can try ALLEXCEPT() function in your code.

Measure 1 = 
VAR _PREVIOUSDATE =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Customer ID] ),
            'Table'[Date] < MAX ( 'Table'[Date] )
        )
    )
RETURN
    IF ( _PREVIOUSDATE = BLANK (), 0, 1 )
Measure 2 = 
MAXX(ALLEXCEPT('Table','Table'[Customer ID]),[Measure 1])

Result is as below.

RicoZhou_0-1670566161775.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like but please try something like below whether it suits your requirement.

 

Expected measure 2: =
MAXX (
    CALCULATETABLE ( ALLSELECTED ( Sales ), VALUES ( Sales[Customer ID] ) ),
    [Measure 1]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi Jihwan,
With this im getting some blank values it should either be 0 ore 1,

but result is looking like:

Customer IDDateSaleMeasure 1Measure 2
110/01/20224000
115/02/20225011
112/05/20226011
215/10/20222000
214/11/20223411
315/03/2022230 
314/10/2022341 
 

Hi @Anonymous ,

 

I think you can try ALLEXCEPT() function in your code.

Measure 1 = 
VAR _PREVIOUSDATE =
    CALCULATE (
        MAX ( 'Table'[Date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Customer ID] ),
            'Table'[Date] < MAX ( 'Table'[Date] )
        )
    )
RETURN
    IF ( _PREVIOUSDATE = BLANK (), 0, 1 )
Measure 2 = 
MAXX(ALLEXCEPT('Table','Table'[Customer ID]),[Measure 1])

Result is as below.

RicoZhou_0-1670566161775.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi,

Please share your sample pbix file's link (Onedrive, googledrive, dropbox, ... ) here, and then I can try to look into it to come up with a more accurate solution.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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