Forum Discussion

Roli_Bird's avatar
Roli_Bird
Copper Contributor
Mar 18, 2022
Solved

DAX: Running Total

Hello, everyone. I hope someone can help me.


In a small example I try to describe my problem. These are my data. They show at wich date how many pieces of an article are delivered.

 

I would like to display the inventory in a chart like this:

 

I need to calculate the running total in a measure. With my RunningTotal-measure I get the following result.

 

To display the chart I need the following result. How can I calculate not only the black but also the red numbers in a measure?

 

12 Replies

  • Riny_van_Eekelen's avatar
    Riny_van_Eekelen
    Platinum Contributor

    Roli_Bird Possibly there is a better way. For instance, by making the sequential date list dynamic. But I didn't go so far. The attached file does what you need.

    See if you can get it to work on your end.

    • Roli_Bird's avatar
      Roli_Bird
      Copper Contributor

      Riny_van_Eekelen 

      Now I have one more question. Why do you use a separate table DateList and not just use the calendar?

       

      To me it looks like that will work too.

       

      With calendar only:
      =CALCULATE(
      SUM([Quantity]);
      FILTER(ALLSELECTED('Calendar'[Date]);
      ISONORAFTER('Calendar'[Date];MAX('Calendar'[Date]);DESC)))

       

      Instead of with separate DateList:

      =CALCULATE(
      SUM([Quantity]);
      FILTER(ALLSELECTED('Calendar'[Date]);
      ISONORAFTER('Calendar'[Date];MAX(DateList[DeliveryDate]);DESC)))

       

      What is the difference or why is the additional table DateList required.

    • PeterBartholomew1's avatar
      PeterBartholomew1
      Silver Contributor

      Riny_van_Eekelen 

      Well done!

      It looks utterly alien to me, though.  I did find my way to

      RT:=CALCULATE(
      SUM([Quantity]),
      FILTER(ALLSELECTED('Calendar'[Date]),
      ISONORAFTER('Calendar'[Date],MAX(DateList[DeliveryDate]),DESC)))

      but I am not sure that I could write anything of this nature.  It looks like a sequence of summations, each starting from the top, rather that a rolling accumulation.  Is that the case?

      I did confirm that I could generate the charts from the source data using Excel 365 dynamic arrays but, since that was not required, I deleted the file.

      I did also wonder about a different chart type, namely a scatter chart that uses the vertical error bar to indicate the change in opening to closing balance on a delivery date and the horizontal error bar to bridge between one date and the next.  The hope would be to achieve clean steps rather linking values with sloping lines.

       

    • Roli_Bird's avatar
      Roli_Bird
      Copper Contributor

      Riny_van_Eekelen 

       

      Hello Riny

      Thank you for your solution.

       

      I must have spent a day trying to build the measure without success.

      Your measure does exactly what I need.

       

      I will now look at it carefully so that I understand it too. Then I build it into my dashboard, in which the calendar is of course dynamically created in PowerQuery.

       

      Thank you again for your solution.
      Roland

Resources