Forum Discussion

stanleycj's avatar
stanleycj
Helper I
3 years ago
Solved

Column level difference between two selected dates (ie. Max date - Min date)

Dears, Greetings!   I need the difference between any selected max(date) - min(date) ie. Jan23 - Dec23, as an "Mvt. details" as shown below output format.   Detail_Tbl ID  Name ST VAL BN...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi stanleycj 

    You can refer to the following example.

    1.Create a table

    Type = SUMMARIZE(Detail_Tbl,[BNK]) 

    Then put it into a slicer

    2.Create a new calculated column in date table

    Month = IF([MthYr]="Mvt.",0,MONTH([MIS_Date]))

    3.Then create three measure

    Measure 1 = var a=FILTER(ALLSELECTED(Date_Tbl),[Month]<>0)
    var b=SELECTCOLUMNS(ALL(Detail_Tbl),"a",MONTH(Detail_Tbl[MthYr]))
    var c=FILTER(Detail_Tbl,[BNK] in VALUES('Type'[BNK])&&[ST]=1)
    return IF(SELECTEDVALUE(Date_Tbl[MthYr])="Mvt.",CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=MINX(a,[Month])))-CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=MAXX(a,[Month]))),IF(OR(SELECTEDVALUE(Date_Tbl[Month])=MINX(a,[Month]),SELECTEDVALUE(Date_Tbl[Month])=MAXX(a,[Month]))&&SELECTEDVALUE(Date_Tbl[Month]) in b,CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=SELECTEDVALUE(Date_Tbl[Month])))))
    
    Measure 2 = var a=FILTER(ALLSELECTED(Date_Tbl),[Month]<>0)
    var b=SELECTCOLUMNS(ALL(Detail_Tbl),"a",MONTH(Detail_Tbl[MthYr]))
    var c=FILTER(Detail_Tbl,[BNK] in VALUES('Type'[BNK])&&[ST]=2)
    return IF(SELECTEDVALUE(Date_Tbl[MthYr])="Mvt.",CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=MINX(a,[Month])))-CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=MAXX(a,[Month]))),IF(OR(SELECTEDVALUE(Date_Tbl[Month])=MINX(a,[Month]),SELECTEDVALUE(Date_Tbl[Month])=MAXX(a,[Month]))&&SELECTEDVALUE(Date_Tbl[Month]) in b,CALCULATE(SUM(Detail_Tbl[VAL]),FILTER(c,MONTH([MthYr])=SELECTEDVALUE(Date_Tbl[Month])))))
    
    Total = [Measure 1]+[Measure 2]
    

    Output

     

     

     

    Best Regards!

    Yolo Zhu

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

     

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi stanleycj 

    I placed the type column in the column, and if you want to show b1, b2 can drill down

    Best Regards!

    Yolo Zhu

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