Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Running total with Reset

Hi there,

 

I am trying to create a column that has a running total, but resets if a column has a 1 (if the column has a value of 0, then the score does not reset). I followed this previous post, but I am getting something odd. 

https://community.powerbi.com/t5/Desktop/Running-Total-Reset-based-on-Column-Attribute/m-p/251130

 

The actual line items with dates show the correct running total (with reset). however, the dates that do not have activities show a value of 1090 (which happens to be the running total on 7/29/19). 

For example, based on the data table below, Dates of 12/31/18 to 1/22/19 show a value of 1090, which causes my line chart to be incorrect. 

 

The sample data set is below. What happens is that I choose a single customer id, and have a list of all the activities that the customer had on our website. Each activity is assigned a specific score and these scores are aggregated until they need to be reset, which is denoted by the "Reset score" column (1=reset, 2=no reset).  The "Running score with reset" is what I'm trying to get, but I'm getting scores of 1090 for all the dates that are not listed in the table. . 

 

Here are the calculations I am using:

 

Running Score =
CALCULATE(
sum(Table1'[Activity Score]),
FILTER(
ALLSELECTED(Table1),
Table1[Activity Date] <= max(Table1[Activity Date])))

 

Max Date = maxx(
FILTER(
ALLSELECTED(Table1),
Table1[reset lead score] = 1 && Table1[Activity Date] <= max(Table1[Activity Date])),
Table1[Activity Date])

 

Running Score with Reset =
CALCULATE(
sum(Table1[Activity Score]),
DATESBETWEEN(
Table1[Activity Date],'Measure Table'[Max Date],LASTDATE(Table1'[Activity Date])))

 

Data set:

IdID IndexActivity DateActivity ScoreRunning Scorereset scoreMax DateRunning score with reset
N0EAJ112/30/20185070112/30/201870
N0EAJ212/30/20182070012/30/201870
N0EAJ31/23/20195012011/23/201950
N0EAJ41/24/20195022001/23/2019100
N0EAJ51/24/20195022001/23/2019150
N0EAJ62/12/20195027012/12/201950
N0EAJ72/17/20195039012/17/2019120
N0EAJ82/17/20195039002/17/2019120
N0EAJ92/17/20192039002/17/2019120
N0EAJ102/26/20195049012/26/2019100
N0EAJ112/26/20195049002/26/2019100
N0EAJ123/5/20195054013/5/201950
N0EAJ133/11/20195059013/11/201950
N0EAJ143/19/20195064013/19/201950
N0EAJ153/21/20195069013/21/201950
N0EAJ163/22/20195074003/21/2019100
N0EAJ173/24/20195079003/21/2019150
N0EAJ183/28/20195084013/28/201950
N0EAJ194/24/2019084003/28/201950
N0EAJ205/8/20195089015/8/201950
N0EAJ216/4/20195094016/4/201950
N0EAJ226/7/20195099006/4/2019100
N0EAJ237/22/201950104017/22/201950
N0EAJ247/29/201950109007/22/2019100

 

This is a sample of the resulting table I'm getting with my current calculations. 

 

 

Any assistance would be great! 

 

Thank you. 

 

  • Anonymous's avatar
    Anonymous
    7 years ago

    Thanks for your input. I was able to figure out. 

    Basically what was happening it was calling the customer ID from a different table instead of within the same table. Once I did this minor change, it worked. 

     

    (Like you, I tried it with the simple table I sent in my original post, and it worked with the same calculations and measures). 

     

    Thanks!

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    This is a sample of the data I'm getting when I run the above set of queries. 

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

      hi, Anonymous 

      I have test on my side, it works well on my side.

       

      Could you please share your sample pbix file for us have a test? there may be something wrong in other.

       

      Best Regards,

      Lin

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        Thanks for your input. I was able to figure out. 

        Basically what was happening it was calling the customer ID from a different table instead of within the same table. Once I did this minor change, it worked. 

         

        (Like you, I tried it with the simple table I sent in my original post, and it worked with the same calculations and measures). 

         

        Thanks!