Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Add rows for misisng years

Hello Folks,   I am trying to add rows based on certain condition.   Any leads please?   Data: MembershipID     InceptionDate(YYYYMM)     MembershipGroup      AccountBalance    1 202...
  • v-angzheng-msft's avatar
    4 years ago

    Hi, Anonymous 

    Create a calculation table as follows:

    T = 
    var _t=ADDCOLUMNS('Table',"maxTo",[_Max],"minTo",[_min])
    var _id_to=SUMMARIZE(_t,'Table'[MembershipID],'Table'[MembershipGroup],[maxTo],[minTo])
    
    var _id=SUMMARIZE('Table','Table'[MembershipID],'Table'[MembershipGroup])
    var _maxOfAll=Value([_Max])
    var _minOfAll=Value([_min])
    
    var _GenerateTable=GENERATE(_id,GENERATESERIES(_minOfAll,_maxOfAll))
    var _Fact=FILTER(_GenerateTable,[MembershipID]='Table'[MembershipID]&&[MembershipGroup]='Table'[MembershipGroup]&&
            ''[Value]<=MAXX(FILTER(_id_to,[MembershipID]=EARLIER([MembershipID])&&[MembershipGroup]=EARLIER([MembershipGroup])),Value([maxTo]))&&''[Value]>=MINX(FILTER(_id_to,[MembershipID]=EARLIER([MembershipID])&&[MembershipGroup]=EARLIER([MembershipGroup])),Value([minTo]))&&Value(RIGHT(CONVERT(''[Value],STRING),2))<=12&&Value(RIGHT(CONVERT(''[Value],STRING),2))>=1
            )
    
    return _Fact

    Create 2 measures to get the maximum year-month and the minimum year-month.

    _Max = 
    CALCULATE(MAX('Table'[InceptionDate(YYYYMM)]),ALLEXCEPT('Table','Table'[MembershipID],'Table'[MembershipGroup]))
    _min = 
    CALCULATE(MIN('Table'[InceptionDate(YYYYMM)]),ALLEXCEPT('Table','Table'[MembershipID],'Table'[MembershipGroup]))

    Finally create a calculated column to get the result.

    Account = 
    var _account=
    LOOKUPVALUE('Table'[AccountBalance],'Table'[MembershipID],[MembershipID],'Table'[MembershipGroup],[MembershipGroup],'Table'[InceptionDate(YYYYMM)],CONVERT([Value],STRING))
    var _table=
    FILTER(ALL('Table'),
            'Table'[MembershipID]=EARLIER(T[MembershipID])
            &&'Table'[MembershipGroup]=EARLIER(T[MembershipGroup])
            &&Value('Table'[InceptionDate(YYYYMM)])<=EARLIER([Value])
            )
    var _fillDown=
    CALCULATE(
            Min('Table'[AccountBalance]),
            _table
        )
    var _ifBlank=IF(ISBLANK(_account),_fillDown,_account)
    
    return _ifBlank


    Result:

    Please refer to the attachment below for details. Hope this helps.

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.