Forum Discussion

ahorne27's avatar
ahorne27
New Member
8 years ago
Solved

Accumulative values from a count

Hi All

 

I am struggling to plot data that accumulates the values from a count.

 

To illustrate what I am trying to do I have created the table in Excel

 

Item NameCost Per Item x Number SoldTimestampTotal
Box601/02/20176
Box5602/02/201762
Box807/05/201770
Letter1206/05/201712
Letter57704/08/2017589
Letter7817/01/2017667

 

The total column is the column that I am unable to create in PowerBI.  Does anyone know how to do this in a DAX expression?

 

Thanks, Ashley

  • ahorne27,

     

    You may also refer to the following DAX that creates a measure.

    Measure =
    VAR n =
        MAX ( Table1[Item Name] )
    VAR t =
        MAX ( Table1[Timestamp] )
    RETURN
        CALCULATE (
            SUM ( Table1[Cost Per Item x Number Sold] ),
            FILTER (
                ALLSELECTED ( Table1 ),
                Table1[Item Name] = n
                    && Table1[Timestamp] <= t
            )
        )
    

4 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Hi Ashley ahorne27

     

    Add this Calculated Column to get Cumulative Values or Running Totals :smileywink:

    RunningTotal =
    SUMX (
        FILTER (
            Table1,
            Table1[Item Name] = EARLIER ( Table1[Item Name] )
                && Table1[Timestamp] <= EARLIER ( Table1[Timestamp] )
        ),
        Table1[Cost Per Item x Number Sold]
    )


  • v-chuncz-msft's avatar
    v-chuncz-msft
    Community Support

    ahorne27,

     

    You may also refer to the following DAX that creates a measure.

    Measure =
    VAR n =
        MAX ( Table1[Item Name] )
    VAR t =
        MAX ( Table1[Timestamp] )
    RETURN
        CALCULATE (
            SUM ( Table1[Cost Per Item x Number Sold] ),
            FILTER (
                ALLSELECTED ( Table1 ),
                Table1[Item Name] = n
                    && Table1[Timestamp] <= t
            )
        )
    
  • Hi ahorne27,

     

    You may also try this calculated column formula

     

    =CALCULATE(SUM(Table1[Cost Per Item x Number Sold]),FILTER(Table1,Table1[Item Name] = EARLIER(Table1[Item Name])&&Table1[Timestamp]<=EARLIER(Table1[Timestamp])))

    Hope this helps.

  • Thanks everyone for such quick replies!  In the end the measure worked best with my content.