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
Anonymous
Not applicable

Flag column all dates based on two dates

Hi All,

 

In the flag column I would like to see 1 (or true / false) if the date is between the start and enddate. The startdate is based on the Quantity column, if the quantity is larger then 12, the next 12 months needs to be flagged.

 

Who can come up with a solution? 

RHBIP_0-1663867439584.png

 

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Anonymous 

please try

flag column =
VAR CurrentDate = 'Table'[Date]
VAR CurrentStart = 'Table'[Date_start]
VAR CurrentEnd = 'Table'[Date_end]
VAR StartDate = CurrentDate - 365
VAR TableBefore =
    FILTER ( 'Table', 'Table'[Date] <= CurrentDate && 'Table'[Date] >= StartDate )
VAR MatchingRecords =
    FILTER (
        TableBefore,
        'Table'[Date] >= CurrentStart
            && 'Table'[Date] <= CurrentEnd
    )
VAR Quantity =
    MAXX ( MatchingRecords, 'Table'[Quantity] )
RETURN
    IF (
        CurrentDate >= CurrentStart
            && CurrentDate <= CurrentEnd,
        1,
        IF ( Quantity >= 12, 1 )
    )
Anonymous
Not applicable

Hi @tamerj1 

 

Only thing missing are the flags I added in red. From 21-7-2022 untill 21-7-2023 every row should get a flag because from the month the quantity > 12 every row needs a flag until the date_end.

 

RHBIP_1-1663916209929.png

 

 

 

 

Greg_Deckler
Community Champion
Community Champion

@Anonymous Try:

flag column =
  VAR __Date = [Date]
  VAR __Start = MAXX(FILTER('Table',[Quantity]>12 && [Date]<=__Date),[Date_start])
  VAR __End = MAXX(FILTER('Table',[Quantity]>12 && [Date]<=__Date),[Date_end])
RETURN
  IF(__Date <= __End && __Date >= __Start),1,BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi Greg,

Thanks for the quick reply. The flags in green are correct, but the red ones are not. Can't figure out why they are flagged..

 

RHBIP_0-1663870396774.png

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.