Forum Discussion

VoltesDev's avatar
VoltesDev
Helper V
4 years ago
Solved

Need help on classifying value

Hello guys,   Need you help on my issue here, that if I have this kind of data : What I need is to calculate the age of the ending qty.    I have a setup of grouping to classify the age li...
  • v-yalanwu-msft's avatar
    4 years ago

    Hi, VoltesDev ;

    Try it.

    Measure = 
    var _1m=CALCULATE(SUM([Qty]),FILTER(ALL('Table'),[Item]=MAX('Table'[Item])&&[month]="1 month"))
    var _2m=CALCULATE(SUM([Qty]),FILTER(ALL('Table'),[Item]=MAX('Table'[Item])&&[month]="2 month"))
    var _3m=CALCULATE(SUM([Qty]),FILTER(ALL('Table'),[Item]=MAX('Table'[Item])&&[month]=">2 month"))
    var   _total=SWITCH( MAX([month]),"1 month",IF(_1m+_2m> 0&&_1m<0,_1m+_2m,0),"2 month",IF(_1m+_2m<0,_1m+_2m+_3m,_2m),">2 month",IF(_1m<0&&_1m+_2m>0,_3m-_2m,0))
    return IF(HASONEVALUE('Table'[month]),_total,SUM('Table'[Qty]))

    The final output is shown below:

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.