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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JayJay0368
Frequent Visitor

How do I flag every instance?

Hi people,

I need you help with the following:

I have a Table in Power BI which shows the following:

JayJay0368_0-1686753446837.png

 

now, I want to make a column, which calculates the following logic:

 

When there has been a visit ("Date of visit (flag)"=1) in a store (in this example "Store 1"), I need to flag the first date AFTER the visit where the Product (in this example "Product 1") is not present ("Product is not present"=1).

 

I have tried to make the following DAX calculation (Calculated column):

 

First Instance of "product not present" after "visit" (flag) =

IF(
    COUNTROWS(
        FILTER(
            'Table',
            'Table[customer] = EARLIER('Table'[customer]) &&
            'Table'[Product] = EARLIER('Table'[Product]) &&
            'Table'[Date] <= EARLIER('Table'[Date])&&
            'Table'[Date of Visit (flag)]=1 
        )
    ) >= 1,
    IF(
    COUNTROWS(
        FILTER(
            'Table',
            'Table[customer] = EARLIER('Table'[customer]) &&
            'Table'[Product] = EARLIER('Table'[Product]) &&
            'Table'[Date] <= EARLIER('Table'[Date])&&
            'Table'[Product not present (flag)]=1 
        )
    ) = 1,1,0))

 

 

 

RESULT:

JayJay0368_1-1686753446847.png

 

which is close. But I need a "flag" for EVERY time there has been a visit and the product is not present afterwards. I the calculation I have made it only shows the first time. 

 

What I need is the above example is this result:

 

one more visit is taking place on the "09-05-2023" and the product is (still) not present, so I need another flag on the date after the visit date, "14-05-2023". And everytime the combination of "visit date" and "product not present" turns up. 

 

 Picture1.png

 

I have added a link to a spreadsheet with the table used as an example:

example - table 

 

Any help or guidance is REALLY appreciated. Thanks.

 

Br,

Jayjay0306 

2 REPLIES 2
lbendlin
Super User
Super User

Please indicate the expected outcome based on your sample data.

no outcome due to no replies.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.