Forum Discussion

mgantt87's avatar
mgantt87
Regular Visitor
2 years ago
Solved

Sum LASTDATE Total Issue

I am having trouble getting my totals to calculate correctly for the example below in which a sum filtering by LASTDATE is used.  I understand the measure is calculating on the total line, so that's why it's producing an undesired result, but I haven't been able to figure out how to make the total correct.

 

In the example below, my page has a filter where filter column = Y (so the 4/30/2024 row for item A is excluded).  The desire is to show the value from the value column for each item where the date is the largest within each item.  So, for A, it should show a value of 3 from the 3/31/2024 record and for B, it should show a value of 4 from the 4/30/2024 record.  The totals row should add these two values together for a total of 7.  The DAX below is working correctly for each row, but the total is showing 4 (which it is picking up from the 4/30/2024 B record).  How can I make this total show 7?


Measure = CALCULATE(SUM('Data'[Value]), LASTDATE('Data'[Date]))

Data:

ItemValueFilter ColumnDate
A1Y1/31/2024
A2Y2/29/2024
A3Y3/31/2024
A3N4/30/2024
B1Y1/31/2024
B2Y2/29/2024
B3Y3/31/2024
B4Y4/30/2024

 

Expected Result:

ItemMeasureLatest Date
A33/31/2024
B44/30/2024
Total7---

 

Current Result:

ItemMeasureLatest Date
A33/31/2024
B44/30/2024
Total4---

 

 

  • You may have to use the SUMX function for this.

    If you don't have an existing table where your values are equal to your measure, then consider the following:

    Measure = 
    VAR _SumTable = 
    Summarize(
    Data[Item],
    "Measure",CALCULATE(Data[Value],LASTDATE(Data[Date])
    )
    
    RETURN
    SUMX(_SumTable,
    [Measure]
    )

3 Replies

  • ExcelMonke's avatar
    ExcelMonke
    Icon for Impactful Individual rankImpactful Individual

    You may have to use the SUMX function for this.

    If you don't have an existing table where your values are equal to your measure, then consider the following:

    Measure = 
    VAR _SumTable = 
    Summarize(
    Data[Item],
    "Measure",CALCULATE(Data[Value],LASTDATE(Data[Date])
    )
    
    RETURN
    SUMX(_SumTable,
    [Measure]
    )