Forum Discussion

vijay_27's avatar
vijay_27
Icon for Helper I rankHelper I
4 years ago
Solved

Dynamic two month calculation like Dec 2021 + jan 2022

Hello All, I need in Power BI Desktop: I need simple calculation with respect to All 12 months like: jan2021+feb2021 value, feb2021+mar2021 value,-----------Nov2021+Dec2021 Then Dec2021 + Jan2022 v...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi vijay_27 ,

     

    1. Let's assume the MonthCombine is not include in data source, you could use the following formula to get it:

    MonthCombine = [Month]&" + " &CALCULATE(MAX('Table'[Month]),FILTER('Table',[Rank]=EARLIER('Table'[Rank])+1)) 

     

    2. Then please create rank column in order to get the value of next month :

    YeearMonth = [Year]*100+MONTH( CONVERT([Year]&" "&[Month]&" 1", DATETIME) )
    Rank = RANKX('Table',[YeearMonth],,ASC,Dense)

    3. Sort MonthCombine column by Rank, the final table is as shown below:

     

     

    Finally, create a measure:

    Measure = SUM('Table'[Value])+ CALCULATE(SUM('Table'[Value]),FILTER(ALLSELECTED('Table'),[Rank]=MAX('Table'[Rank])+1))

    Output:

     

     

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