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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Pbiuserr
Post Prodigy
Post Prodigy

Flag all months up to current in datetable doesnt work

Hello,

I encounter a problem where I cannot flag with value of 1 all previous months up until current (included).
My measure is rather simple

Flag = IF('date'[Month]MONTH(TODAY()) && 'date'[Year] < YEAR(TODAY()), 1,0)

tried with <= MONTH but it gives me only January for each year.
Does it imply that its not possible because no month is less than January? or how to implement such flag
1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Pbiuserr ,

 

You could create a flag as below:-

Flag = IF('Date_Table'[Date] <=EOMONTH(TODAY(),0),1,0)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

4 REPLIES 4
Samarth_18
Community Champion
Community Champion

Hi @Pbiuserr ,

 

You could create a flag as below:-

Flag = IF('Date_Table'[Date] <=EOMONTH(TODAY(),0),1,0)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Ha, works but no idea why mine code does not.. Do you know how to make the lenght of the slicer only for consecutive 5 years? so from 2018 till current month, I have data from 90's included

That's because you were working on month and year columns whereas he is using the date column. 
Just add to that column: =
Flag =
IF('Date_Table'[Date] <=EOMONTH(TODAY(),0)
&& YEAR('Date_Table'[Date]) >= YEAR(TODAY())-5
,1
,0)

 

@Pbiuserr , Create a measure as below and use it as visual level filter on slicer:-

_filter_year = 
VAR _year =
    YEAR ( TODAY () )
VAR _month =
    MONTH ( TODAY () )
VAR _day =
    DAY ( TODAY () )
VAR _date =
    DATE ( _year - 5, _month, _day ) + 1
RETURN
    IF (
        SELECTEDVALUE ( 'Date_Table'[Date] ) >= _date
            && SELECTEDVALUE ( 'Date_Table'[Date] ) <= TODAY (),
        1,
        0
    )

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.