Forum Discussion

DavidWaters100's avatar
DavidWaters100
Icon for Post Patron rankPost Patron
5 years ago
Solved

Running total not working as expected

Hi,

 

I am trying to return running total in the following measure.  My "main table" is joined to a "Dev Months" table which contains all month numbers, whereas the main table can contains gaps, depending on what slicer is selected by a user, so this solution allows all months to show in the table even if they are not in a particular selection.  However as per below, the running total does not work!  I'm wondering if anyone has a solution to offer please?  I'm thinking I need to add in a return last non-blank, perhaps?

 

thanks!

 

Premium running total =
CALCULATE(
    SUM('Main Table'[Total]),
    FILTER(
        ALLSELECTED('Dev months'[Dev Month]),
        ISONORAFTER('Dev months'[Dev Month], MAX('Main Table'[Development Month ]), DESC)
    ))
 

  • MFelix's avatar
    MFelix
    5 years ago

    Hi DavidWaters100 ,

     

    Believe that your filtering is incorrect because of the way you are using the MAX.

     

    Since you have a relationship between both tables when you use the syntax  

     ISONORAFTER('Dev months'[Dev Month], MAX('Main Table'[Development Month ])

    Basically you are picking up the values even if there aren't any data believe that you need to use something similar to:

    FILTER (DevMonth; DevMonth[Month] <= MAXX(ALL(MainTable[Development Month]);MainTable[Development Month]))

     

    Be aware that I have writen this by head, did not make any test with any data.

6 Replies

  • update - just realised if I change the Max to 'Dev months'[Dev Month]), it does work.

     

    However the Max is there to stop values returning when the dev month gets too high - for example for year 2020, there are only 9 dev months to September.  I need to prevent "future" dev months from showing values!

    • DavidWaters100's avatar
      DavidWaters100
      Icon for Post Patron rankPost Patron

      Hi MFelix 

       

      OK thanks, will look to produce a mock-up.  The problem has evolved to become: how to stop the values when the max that exists for each year in the data is reached - 9 in this case (Dev month is a stand-alone joined table here)

       

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi DavidWaters100 ,

         

        Believe that your filtering is incorrect because of the way you are using the MAX.

         

        Since you have a relationship between both tables when you use the syntax  

         ISONORAFTER('Dev months'[Dev Month], MAX('Main Table'[Development Month ])

        Basically you are picking up the values even if there aren't any data believe that you need to use something similar to:

        FILTER (DevMonth; DevMonth[Month] <= MAXX(ALL(MainTable[Development Month]);MainTable[Development Month]))

         

        Be aware that I have writen this by head, did not make any test with any data.