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
Telstar
Helper I
Helper I

Help with measure to get the "last amount with a value" from a date list

Hi All

Have a measure issue that I cannot solve and need your help
I have the following table of values

DateCodeAmount
31/03/2022200100
31/03/20222501000
30/04/2022200100
30/04/20222502000
31/05/2022200100
31/05/20222503000
30/06/2022200100
30/06/20222504000
31/07/2022200100
31/07/20222505000
31/08/2022200100
31/08/20222506000
30/09/2022200100
30/09/20222507000
31/10/2022200100
31/10/20222508000
30/11/2022200100
30/11/20222509000
31/12/2022200100
31/12/202225010000
31/01/2023200100
28/02/2023200100
31/03/2023200100
30/04/2023200100
31/05/2023200100
30/06/2023200100
31/07/2023200100
31/08/2023200100
30/09/2023200100
31/10/2023200100
30/11/2023200100
31/12/2023200100

 

What I need to accomplish is a "total to date" for code 200 and the last value for code 250
So from the above it would be
31/12/2023 - 200 - 2200 ~ sum of all the values for code 200
31/12/2023 - 250 - 10000 ~ last value for code 250

I am struggling with the DAX to get the 10000 amount - I have tried CALCULATE(SUM(AMOUNT), MAX (DATE),CODE="250") but obviously that gives me 0 - what am I missing.

Help much appreciated

Thanks

Telstar 

1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @Telstar 

Try this measure:

Measure = 
VAR lastDate_ =
    CALCULATE (
        CALCULATE ( MAX ( Table1[Date] ), Table1[Code] = 250 ),
        ALLSELECTED ( Table1 )
    )
RETURN
    CALCULATE (
        DISTINCT ( Table1[Amount] ),
        Table1[Code] = 250,
        Table1[Date] = lastDate_
    )

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

Hi @Telstar 

Try this measure:

Measure = 
VAR lastDate_ =
    CALCULATE (
        CALCULATE ( MAX ( Table1[Date] ), Table1[Code] = 250 ),
        ALLSELECTED ( Table1 )
    )
RETURN
    CALCULATE (
        DISTINCT ( Table1[Amount] ),
        Table1[Code] = 250,
        Table1[Date] = lastDate_
    )

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Thanks for the quick solution @AlB - worked perfectly

Much appreciated.

Telstar

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.