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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Defining date cycles in a table via a Boolean (PowerBI, Python)

Consider the following table consisting of a Date and Item column:

 

DateItem
April 2X
April 3X
April 5X
April 11X
April 12X
April 14X
April 20X
April 2Y
April 3Y
April 9Y
April 11Y
April 12Y
April 14Y

 

I would like to add an additional column called StartFlag containing Boolean values that indicate if an item "entered" this list, and by "enter" we understand the following:

 

An item "enters" the list if it was not on the list for the past 5 days.

 

Hence, the above table should result in the following:

 

DateItemStartFlag
April 2XTRUE
April 3XFALSE
April 5XFALSE
April 11XTRUE
April 12XFALSE
April 14XFALSE
April 20XTRUE
April 2YTRUE
April 3YFALSE
April 9YTRUE
April 11YFALSE
April 12YFALSE
April 14YFALSE

 

Does someone have a solution for this problem (I am also able to run a Python script on my data so that could also lead to a solution.)

 

Thank you.

1 ACCEPTED SOLUTION

Hi,

This calculated column formula works

=ISBLANK(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item]=EARLIER(Data[Item])&&Data[Date]>=EARLIER(Data[Date])-5&&Data[Date]<EARLIER(Data[Date]))))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
vanessafvg
Super User
Super User

you can try a measure like this

StartFlag =
VAR items =
    SELECTEDVALUE ( StartFlag[Item] )
VAR currdate =
    SELECTEDVALUE ( StartFlag[Date] )
VAR maxdate =
    CALCULATE (
        MAX ( StartFlag[Date] ),
        StartFlag[Date] < currdate
            && StartFlag[Item] = items
    )
RETURN
    IF (
        ISBLANK ( maxdate ),
        TRUE (),
        IF ( DATEDIFF ( maxdatecurrdateDAY ) <= 5FALSE ()TRUE () )
    )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

Thank you for your response. Could I get it as a calculated column instead of a measure as well?

Hi,

This calculated column formula works

=ISBLANK(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Item]=EARLIER(Data[Item])&&Data[Date]>=EARLIER(Data[Date])-5&&Data[Date]<EARLIER(Data[Date]))))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Would you be able to define this in PowerQuery too? (sorry for this additional question, turns out I couuldn't use it properly via a calculated column in the end)

Why could you not use it properly via a calculated column?  As you can see in my screenshot, it works just fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

My knowledge of PowerBI is quite limited but here is my problem: after adding this flag I want to filter on it and join it with other tables. (The example I gave you is highly simplified.) Those 'table operations' I only manage in PowerQuery unfortunately...

 

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors