Forum Discussion

Adamkowalsky92's avatar
Adamkowalsky92
Frequent Visitor
1 year ago
Solved

Incorrect SUM

Hey, I need help with a simple formula. At first glance dax I wrote it is simple and in the lines it works correctly however the sum no longer match.

The formula is supposed to search for the max date with the data and subtract the previous day, but since the lines have different max dates, I want the sum of these differences, not the total for example 05.02 - 04.02

As in the image below from the green values, the red values should be subtracted. The expected result for the total is 55, with -125 received, for obvious reasons.



Thanks for help

  • I resolves problem myself ny using

    SUMX(
        SUMMERIZE(
                  Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date]))),Sum)

    _


    SUMX(
        SUMMERIZE(
                  Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date])-1)),Sum)

     

6 Replies

      • bhanu_gautam's avatar
        bhanu_gautam
        Super User

        Adamkowalsky92 Try using

         

        dax
        VAR maxday = MAX(Sales[Day])
        VAR beforeday = CALCULATE(MAX(Sales[Day]), Sales[Day] < maxday)
        VAR sales = CALCULATE(SUM(Sales[Value]), Calendar[Date] = maxday)
        VAR salesbefore = CALCULATE(SUM(Sales[Value]), Calendar[Date] = beforeday)
        RETURN
        SUMX(
        VALUES(Sales[Day]),
        sales - salesbefore
        )

  • Adamkowalsky92's avatar
    Adamkowalsky92
    Frequent Visitor

    I resolves problem myself ny using

    SUMX(
        SUMMERIZE(
                  Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date]))),Sum)

    _


    SUMX(
        SUMMERIZE(
                  Sales,Sales[Client],"Sum",CALCULATE(SUM(Sales[Value]),Sales[Date]=MAX(Sales[Date])-1)),Sum)