cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
APMarsh
Frequent Visitor

Sum of most recent values across time

Hello,

 

I have tried various functions and have not been able to come up with a solution to this.

 

I have a series of reports that are submitted with a number of projects (reference number). I need to track the latest EFC across time at a reference number level.

 

I have tried numerous methods, one of which is:

var test3XX = 
SUMX(
SUMMARIZE('Prog report data',
'Prog report data'[Reference Number],"Reference number",
CALCULATE(SUM('Prog report data'[Estimated Final Cost]),
USERELATIONSHIP('Date'[Date],'Prog report data'[Lodgement date]),
FILTER('Prog report data','Prog report data'[Lodgement date]=MAX('Prog report data'[Lodgement date])),
FILTER(ALL('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])),
FILTER(ALL('Date'[Date]),'Date'[Date]<>BLANK())
)),
[Reference number]
)

 

The issue seems to be that all the functions only return ONE MAX/LATEST date - so when filtering on a project (reference) it is ok, however, when slicing and dicing at an aggregated level, it doesnt recognise the latest lodgement date for each reference number.

 

The data looks something like this (redacted).

 

Reference NumberReport NumberLodgement date Estimated Final Cost
ABC.0002.1819I.SXGABC.PR03.1819.SXG09/04/2020 $                          111,111.11
ABC.0002.1819I.SXGABC.PR01.1819.SXG11/02/2020 $                          111,111.11
ABC.0002.1819I.SXGABC.PR05.1819.SXG12/06/2020 $                          111,111.11
ABC.0002.1819I.SXGABC.PR06.1819.SXG17/07/2020 $                          111,111.11
ABC.0002.1819I.SXGABC.PR08.1819.SXG15/09/2020 $                          111,111.11
ABC.0004.1819E.FGHABC.PR03.1819.FGH01/07/2020 $                          286,729.76
ABC.0004.1819E.FGHABC.PR06.1819.FGH09/11/2020 $                          268,972.07
ABC.0004.1819E.FGHABC.PR04.1819.FGH18/09/2020 $                          268,972.07
ABC.0004.1819E.FGHABC.PR10.1819.FGH10/12/2020 $                          268,972.07
ABC.0014.1819E.FGHABC.PR03.1819.FGH01/07/2020 $                          397,962.54
ABC.0014.1819E.FGHABC.PR06.1819.FGH09/11/2020 $                          326,679.50
ABC.0014.1819E.FGHABC.PR04.1819.FGH18/09/2020 $                          324,312.77
ABC.0014.1819E.FGHABC.PR10.1819.FGH10/12/2020 $                          326,679.50
XYZ.0001.1819I.SXGXYZ.PR01.1819.SXG05/12/2019 $                            23,961.11
XYZ.0001.1819I.SXGXYZ.PR02.1819.SXG28/01/2020 $                            23,961.11
XYZ.0001.1819I.SXGXYZ.PR03.1819.SXG25/02/2020 $                            23,961.11
XYZ.0001.1819I.SXGXYZ.PR05.1819.SXG11/03/2020 $                            23,961.11
XYZ.0001.1819I.SXGXYZ.PR06.1819.SXG13/05/2020 $                            23,961.11
XYZ.0002.1920A.LIPXYZ.PR03.1920.LIP09/06/2020 $                              5,112.99
XYZ.0002.1920A.LIPXYZ.PR01.1920.LIP13/05/2020 $                              5,112.99
XYZ.0003.1920K.FGHXYZ.PR05.1920.FGH10/12/2020 $                          455,466.64
XYZ.0003.1920K.FGHXYZ.PR03.1920.FGH04/11/2020 $                          530,471.67
XYZ.0003.1920K.FGHXYZ.PR02.1920.FGH23/09/2020 $                          460,416.67
XYZ.0003.1920K.FGHXYZ.PR01.1920.FGH21/08/2020 $                          460,416.67
XYZ.0005.1920K.FGHXYZ.PR05.1920.FGH10/12/2020 $                      1,400,645.44
XYZ.0005.1920K.FGHXYZ.PR03.1920.FGH04/11/2020 $                      1,481,465.83
XYZ.0005.1920K.FGHXYZ.PR02.1920.FGH23/09/2020 $                      1,355,555.56
XYZ.0005.1920K.FGHXYZ.PR01.1920.FGH21/08/2020 $                      1,355,555.56
XYZ.0006.1920K.FGHXYZ.PR01.1920.FGH21/08/2020 $                          144,166.67
XYZ.0006.1920K.FGHXYZ.PR02.1920.FGH23/09/2020 $                          144,166.67
XYZ.0006.1920K.FGHXYZ.PR03.1920.FGH04/11/2020 $                          144,166.67
XYZ.0006.1920K.FGHXYZ.PR05.1920.FGH10/12/2020 $                          144,166.67
5 REPLIES 5
amitchandak
Super User
Super User

@APMarsh , Try a measure like

calculate(sum(Table[Estimated Final Cost]), filter(Table,Table[Lodgement date] = calculate(max(Table[Lodgement date]), allexpcept(Table,table[Reference Number]))))



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Hi Amitchandak,

Thanks for the suggestions. I did try this function as well - and it doesnt get the result i need. It needs to be able to sum across time (similar to a cumulative...but only summing the latest value). 

 

For example:

Dax problem.png

 

 

 

 

 

The sum on Wed night is 38.

The sum on Thurs night = 2+7+20+3+1+6+0 = 39

 

When i use any of the below code it works ok when i filter on a single reference number, however when I filter at the aggregated level, it doesnt work.

 

 

 

var test2 = 
CALCULATE(SUM('Prog report data - CUBE'[Estimated Final Cost]),
    FILTER('Prog report data - CUBE','Prog report data - CUBE'[PR lodgement date]=
    CALCULATE(MAX('Prog report data - CUBE'[PR lodgement date]),
    USERELATIONSHIP('Date'[Date],'Prog report data - CUBE'[PR lodgement date]),
    FILTER(ALL('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])),
    FILTER(ALL('Date'[Date]),'Date'[Date]<>BLANK())
    )))

var test3 = 
SUMX(
    SUMMARIZE('Prog report data - CUBE',
    'Prog report data - CUBE'[Submission Number],"Sub NumberX",
    CALCULATE(SUM('Prog report data - CUBE'[Estimated Final Cost]),
        //FILTER('Prog report data - CUBE','Prog report data - CUBE'[PR lodgement date]=MAX('Prog report data - CUBE'[PR lodgement date]))
        USERELATIONSHIP('Date'[Date],'Prog report data - CUBE'[PR lodgement date]),        
        FILTER(ALL('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])),
        FILTER(ALL('Date'[Date]),'Date'[Date]<>BLANK())
        )
    ),[Sub NumberX]
)

var test4 = 
CALCULATE(test3,
    //FILTER('Prog report data - CUBE','Prog report data - CUBE'[PR lodgement date]=MAX('Prog report data - CUBE'[PR lodgement date]))
    USERELATIONSHIP('Date'[Date],'Prog report data - CUBE'[PR lodgement date]),        
    FILTER(ALL('Date'[Date]),'Date'[Date]<=MAX('Date'[Date])),
    FILTER(ALL('Date'[Date]),'Date'[Date]<>BLANK())
)

var test5 = 
CALCULATE(
    SUM('Prog report data - CUBE'[Estimated Final Cost]),
    FILTER('Prog report data - CUBE','Prog report data - CUBE'[PR lodgement date]=CALCULATE(MAX('Prog report data - CUBE'[PR lodgement date]),
        ALLEXCEPT('Prog report data - CUBE','Prog report data - CUBE'[Submission Number])))
)

 

 Plotting over time doesnt work at aggregated level:

 

 

Dax problem2.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

@APMarsh , Try a measure like

 

Measure =
VAR __id = MAX ('Table'[Reference Number] )
VAR __date = CALCULATE ( MAX('Table'[Lodgement date] ), ALLSELECTED ('Table' ), 'Table'[Reference Number] = __id )
CALCULATE ( Min ('Table'[Estimated Final Cost] ), VALUES ('Table'[Reference Number] ),'Table'[Reference Number] = __id,'Table'[Lodgement date ] = __date )



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!

Hi @amitchandak ,

 

Have you had any further thoughts about this one. I still haven't managed to find a solution. 

Thanks Amitchandak,

 

I tried the below measure but it seems to give an uexpected result. 

 

 

var max1X = MAX('Prog report data - CUBE'[Submission Number])
 
var dateXX = CALCULATE(MAX('Prog report data - CUBE'[PR lodgement date]),ALLSELECTED('Prog report data - CUBE'),'Prog report data - CUBE'[Submission Number]=max1X)
 
return
CALCULATE(MIN('Prog report data - CUBE'[Estimated Final Cost]),VALUES('Prog report data - CUBE'[Submission Number]),'Prog report data - CUBE'[Submission Number]=max1X,'Prog report data - CUBE'[PR lodgement date]=dateXX)

 

 

I will keep trying and let you know when i get it. 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors