Forum Discussion

um_mir's avatar
um_mir
Frequent Visitor
7 years ago
Solved

Cumulative Sum with two filters

Hi Experts,

 

Can someone please help me with below issue. I have data like this:

 

TableA

SequenceNumberYear
1302016
1312016
1322017
1332017
1342018
1352018
1362019

 

Measure [NetGrowth] works good.

 

My [NetGrowth] cumulative measure is

NetGrowthCumulative = 
VAR MyYearMin = MINX(TableA,TableA[Year])
VAR MyYearMax = MAXX(TableA,TableA[Year])
RETURN 
SUMX(
    FILTER(
        ALL(TableA),TableA[SequenceNumber]<=MAX(TableA[SequenceNumber]) 
            && TableA[Year]>=MyYearMin && TableA[Year]<=MyYearMax
        ),
    [NetGrowth]
)

 

 
This [NetGrowthCumulative] measure works for one year window only. It resets for every year. Please see my screen shot below where from 352 to 361 is year 2018 & 362 to 363 is year 2019.
How can i fix this? Any solutions will be much appreciated.
 
Thank you
  • Hello,

     

    I got this working. Hope below solution will help someone:

     

    1. Created a measure in TableA to get selected Year

    SelectedYear = 
    VAR t = ALLSELECTED(TableA[Year])
    RETURN 
    IF(MAX(TableA[Year]) in t,1,0)

    2. Cumulative Measure code

     

    NetGrowthCumulative = 
    SUMX(
        FILTER(
            ALLEXCEPT(TableA,TableA[Year]),
            TableA[SeqNo]<=MAX(TableA[SeqNo]) && [SelectedYear]=1
            ),
    [NetGrowth])

    3. Make sure there is relationship between TableA & TableB.

     

     

    Regards

3 Replies

  • v-frfei-msft's avatar
    v-frfei-msft
    Icon for Community Support rankCommunity Support

    Hi um_mir,

     

    What is your meausre [NetGrowth]? Could you please share your sample data and excepted result to me, if you don't have confidential data? Please upload your file to One Drive and share the link here.

     

    Regards,

    Frank

    • um_mir's avatar
      um_mir
      Frequent Visitor

      Hi v-frfei-msft

       

      Thank you for your quick response. Please see the link for the pbxi file. I have reproduced the issue. Cummulative sum works for a year and it resets again in the next year. For the attached example NetGrowthCumulative I'm exepecting below result:

       

      YearSeqNoNetGrowthNetGrowthCumulative
      20181100100
      2018250150
      2018395245
      20184-50195
      20185120315
      2019620335
      2019780415

       

      Regards

      • um_mir's avatar
        um_mir
        Frequent Visitor

        Hello,

         

        I got this working. Hope below solution will help someone:

         

        1. Created a measure in TableA to get selected Year

        SelectedYear = 
        VAR t = ALLSELECTED(TableA[Year])
        RETURN 
        IF(MAX(TableA[Year]) in t,1,0)

        2. Cumulative Measure code

         

        NetGrowthCumulative = 
        SUMX(
            FILTER(
                ALLEXCEPT(TableA,TableA[Year]),
                TableA[SeqNo]<=MAX(TableA[SeqNo]) && [SelectedYear]=1
                ),
        [NetGrowth])

        3. Make sure there is relationship between TableA & TableB.

         

         

        Regards