Forum Discussion

zbrooks's avatar
zbrooks
Frequent Visitor
5 months ago
Solved

Resetting my cumulative total when it dips below zero

Hi

 

I have a cumulative sum that has a starting total which then needs to be adding a Loadingtotal. this loading total could be positive or negative. if the cumulitive sum goes below zero it should reset and start adding the loading total as if it was starting again but at zero. I have the following as an example

Any help would be appreciated

 

  • Anonymous's avatar
    Anonymous
    5 months ago

    Hi zbrooks ,

    This approach is built in Power Query, so the calculation is done during data load. Because of that, it won’t respond to slicers or filters applied in the report the values will remain static regardless of user interaction.

    If you need the cumulative total to change dynamically based on slicers, then the same logic would need to be implemented using a DAX measure instead.

    Hope this helps.

    Thank you.

12 Replies

  • Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Alternatively, you can share your .pbix via some cloud service and paste the link here. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

     

    Need help uploading data? click here

     

    Want faster answers? click here

    • zbrooks's avatar
      zbrooks
      Frequent Visitor
      DateLoadingTotalStartTotalCumulative_IncorrectCumulative_Correct
      2026/04/012560476573247324
      2026/04/02-1140061846184
      2026/04/03-2847033373337
      2026/04/04-2291010461046
      2026/04/05-17230-6770
      2026/04/06-17070-23840
      2026/04/0717250-6591725
      2026/04/08-4170-10761308
      2026/04/09-4160-1492892
      2026/04/10-740-1566818
      2026/04/11-18230-33890
      2026/04/12-13210-47100
      2026/04/13-2070-49170
      2026/04/1400-49170
      2026/04/1500-49170
      2026/04/1600-49170
      2026/04/1700-49170
      2026/04/1800-49170
      2026/04/1950000835000
      2026/04/2000835000
      2026/04/21-7140-6314286
      2026/04/22-7140-13453571
      2026/04/23-7140-20602857
      2026/04/24-7140-27742143
      2026/04/25-7140-34881429
      2026/04/26-7140-4203714
      2026/04/27-1140-4317600
      2026/04/281450701019115107
      2026/04/29001019115107
      2026/04/30-14530873713654
    • zbrooks's avatar
      zbrooks
      Frequent Visitor
      DateLoadingTotalStartTotalCumulative_IncorrectCumulative_Correct
      2026/04/012560476573247324
      2026/04/02-1140061846184
      2026/04/03-2847033373337
      2026/04/04-2291010461046
      2026/04/05-17230-6770
      2026/04/06-17070-23840
      2026/04/0717250-6591725
      2026/04/08-4170-10761308
      2026/04/09-4160-1492892
      2026/04/10-740-1566818
      2026/04/11-18230-33890
      2026/04/12-13210-47100
      2026/04/13-2070-49170
      2026/04/1400-49170
      2026/04/1500-49170
      2026/04/1600-49170
      2026/04/1700-49170
      2026/04/1800-49170
      2026/04/1950000835000
      2026/04/2000835000
      2026/04/21-7140-6314286
      2026/04/22-7140-13453571
      2026/04/23-7140-20602857
      2026/04/24-7140-27742143
      2026/04/25-7140-34881429
      2026/04/26-7140-4203714
      2026/04/27-1140-4317600
      2026/04/281450701019115107
      2026/04/29001019115107
      2026/04/30-14530873713654
      • FBergamaschi's avatar
        FBergamaschi
        Icon for Super User rankSuper User

        Hi zbrooks 

        is the table you provided me a pure dataset or includes some measure results? I mean: please send me only the raw columns you have and the code of the measures you have already implemented. So I can start from there

         

        Anyway it looks like a recursive calculation at first sight, so better to be done in SQLenvironments but I might be wrong.

         

        Thanks

    • zbrooks's avatar
      zbrooks
      Frequent Visitor
      DateLoadingTotalStartTotalCumulative_IncorrectCumulative_Correct
      2026/04/012560476573247324
      2026/04/02-1140061846184
      2026/04/03-2847033373337
      2026/04/04-2291010461046
      2026/04/05-17230-6770
      2026/04/06-17070-23840
      2026/04/0717250-6591725
      2026/04/08-4170-10761308
      2026/04/09-4160-1492892
      2026/04/10-740-1566818
      2026/04/11-18230-33890
      2026/04/12-13210-47100
      2026/04/13-2070-49170
      2026/04/1400-49170
      2026/04/1500-49170
      2026/04/1600-49170
      2026/04/1700-49170
      2026/04/1800-49170
      2026/04/1950000835000
      2026/04/2000835000
      2026/04/21-7140-6314286
      2026/04/22-7140-13453571
      2026/04/23-7140-20602857
      2026/04/24-7140-27742143
      2026/04/25-7140-34881429
      2026/04/26-7140-4203714
      2026/04/27-1140-4317600
      2026/04/281450701019115107
      2026/04/29001019115107
      2026/04/30-14530873713654
  • zbrooks's avatar
    zbrooks
    Frequent Visitor

    I will prepare a sample Pbix file with measures that i currently use. was just hoping someone has come accross a similiar issue and could point me in the right direction.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi zbrooks ,
    I was able to reproduce this from my end using the same sample data. The issue occurs due to how the cumulative total is evaluated row by row, especially when the running value goes below zero.

    To handle this correctly, I created a duplicate query and implemented the running total using a buffered list with List.Accumulate,, resetting the value to 0 whenever the cumulative result becomes negative. This avoids cyclic reference errors and ensures the calculation remains stable across all rows.

    You can refer to the query in the attached PBIX file , where the cumulative logic is applied and produces the expected output.


    Thank You.

     

    • zbrooks's avatar
      zbrooks
      Frequent Visitor

      Thanks v-sshirivolu

      A quick question, will this work if i have slicers on the page?
      Truly appreciate the solution. Going to have learn some power query for the future.

       
       
      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi zbrooks ,

        This approach is built in Power Query, so the calculation is done during data load. Because of that, it won’t respond to slicers or filters applied in the report the values will remain static regardless of user interaction.

        If you need the cumulative total to change dynamically based on slicers, then the same logic would need to be implemented using a DAX measure instead.

        Hope this helps.

        Thank you.