Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Need previous month flag

I want to add a column with previous 3 month flag in reverse order, when we go to the next month the month prior to it should be flaged as 1

Say we are in June now, I want to have "May" flaged as 1, "Apr" as 2

(when we are in Jan of 2023, Dec 2022 should be flagged as 1 and so on)

 

YearMonthFlag
2021November0
2021December0
2022January0
2022February0
2022March3
2022April2
2022May1
2022June 

 

This is how my data looks like now

CategoryValueFiscal YearFiscal MonthDate
Cate 1 2021October10-01-2020
Cate 1 2021November11-01-2020
Cate 1 2021December12-01-2020
Cate 1 2021January01-01-2021
Cate 1 2021February02-01-2021
Cate 1 2021March03-01-2021
Cate 1 2021April04-01-2021
Cate 1 2021May05-01-2021
Cate 1 2021June06-01-2021
Cate 1 2021July07-01-2021
Cate 1 2021August08-01-2021
Cate 1252021September09-01-2021
Cate 1252022October10-01-2021
Cate 1252022November11-01-2021
Cate 1272022December12-01-2021
Cate 1272022January01-01-2022
Cate 1272022February02-01-2022
Cate 1292022March03-01-2022
Cate 1292022April04-01-2022
Cate 2 2022May05-01-2022
Cate 3 2022June06-01-2022
Cate 4 2022July07-01-2022
Cate 5 2022August08-01-2022
Cate 6 2022September09-01-2022

 

 

Regards

Tanmay

  • Anonymous's avatar
    Anonymous
    4 years ago

    Anonymous , create a Calculated Column with this DAX formula below. That will give you a field that holds the number of months between today's date and the [Date] field in each row.

    Previous3MonthsFlag = DATEDIFF([Date], NOW(), MONTH) 

     Or if you want the measure to only have a value for the three months prior, then do this:

    IF(DATEDIFF([Date], NOW(), MONTH) IN {1,2,3}, DATEDIFF([Date], NOW(), MONTH))

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous , create a Calculated Column with this DAX formula below. That will give you a field that holds the number of months between today's date and the [Date] field in each row.

    Previous3MonthsFlag = DATEDIFF([Date], NOW(), MONTH) 

     Or if you want the measure to only have a value for the three months prior, then do this:

    IF(DATEDIFF([Date], NOW(), MONTH) IN {1,2,3}, DATEDIFF([Date], NOW(), MONTH))