Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

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

1 ACCEPTED SOLUTION
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))

View solution in original post

1 REPLY 1
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))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.