Forum Discussion
Flag Column based on date compare.
Hi,
Trying to create a custom flag column based on below logic but
Calculate Measures:
1.Calendardate - Max(Calendar[Date])
2. Calendardate PY - Date(Year(Calendar[Date])-1,Month(Calendar[Date]),Day(Calendar[Date]))
Flag_Column:
If ([Release Date] <= [Calendardate PY] && if (([Release Date]) >= EDATE(DATE(YEAR(Calendardate PY),MONTH(Calendardate PY),1),-11),"Include","Exclude"))
Above logic works for current month and Current year and Its not working when"Jan" month is selected. I'm expecting Max[Calendar[Date]) to 1/31/2022 but it still considering 2/17/2022.
Any suggestion..
Thanks in Adavance.
Hi kanth123 ,
As amitchandak said, the value of calculated column can't be changed by slicer, they are calculated at data refresh. For more about calculated column, refer to this article: Difference between calculated columns and measures?
Your expected result can also be avhieved in a measure. In a measure, you should use MAX/MIN before a column to return the value in the current row. This is the measure formula.
Flag = IF ( MAX ( [Release Date] ) <= [Calendardate PY] && MAX ( [Release Date] ) >= EDATE ( DATE ( YEAR ( [Calendardate PY] ), MONTH ( [Calendardate PY] ), 1 ), -11 ), "Include", "Exclude" )The value of Flag will change by the selected value in the slicer.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- amitchandakSuper User
kanth123 , if you trying to create a column that should work based on slicer selection. It will not.
The best is to use time intelligence
Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA
Power BI — Qtr on Qtr with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839
https://www.youtube.com/watch?v=8-TlVx7P0A0
Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA
Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8
Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c3243d1f9 - v-yanjiang-msftCommunity Support
Hi kanth123 ,
As amitchandak said, the value of calculated column can't be changed by slicer, they are calculated at data refresh. For more about calculated column, refer to this article: Difference between calculated columns and measures?
Your expected result can also be avhieved in a measure. In a measure, you should use MAX/MIN before a column to return the value in the current row. This is the measure formula.
Flag = IF ( MAX ( [Release Date] ) <= [Calendardate PY] && MAX ( [Release Date] ) >= EDATE ( DATE ( YEAR ( [Calendardate PY] ), MONTH ( [Calendardate PY] ), 1 ), -11 ), "Include", "Exclude" )The value of Flag will change by the selected value in the slicer.
I attach my sample below for reference.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.