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
jmolina
Frequent Visitor

Flag a record by count back days

Hi Guys,.

  

I need some help with my DAX. I want to flag a record by count back days, if is the same ean, store, and stock if stock [date] = stock[previous N days].

 

This is a sample data:

 

sample_count_back_days.PNG

 

 

 

 

Another example:

 

sample_count_back.PNG

 

 

 

 

 Could you help me please?

 

Best!

 

1 ACCEPTED SOLUTION

I think that you want something like:

 

Column = 
VAR __minDate = [date] - 2
VAR __table = FILTER(ALL('Table'),[date]<=EARLIER([date]) && [date]>=__minDate && [store]=EARLIER([store]) && [item]=EARLIER([item]))
VAR __val2day = MAXX(FILTER(__table,[date]=EARLIER([date])-2),[stock qty])
VAR __val1day = MAXX(FILTER(__table,[date]=EARLIER([date])-1),[stock qty])
RETURN
IF(__val2day = [stock qty] && __val1day = [stock qty],1,0)


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hi @jmolina,

 

If you mean mark tag of same store amount, you can try to use following calculated column formula:

Continuous Tag =
VAR prev =
    LOOKUPVALUE (
        'Table'[STOCK],
        'Table'[STORE], [STORE],
        'Table'[EAN], [EAN],
        'Table'[Date], [Date] - 1
    )
VAR next =
    LOOKUPVALUE (
        'Table'[STOCK],
        'Table'[STORE], [STORE],
        'Table'[EAN], [EAN],
        'Table'[Date], [Date] + 1
    )
RETURN
    IF ( [STOCK] IN { prev, next }, 1, 0 )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Greg_Deckler
Super User
Super User

I'm not understanding the logic of when something is 1 or 0.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,.

 

 

I need to flag (1, 0) if the stock quantity maintains static in the last 3 consecutive days, for the same item and store

 

i have updated my post with other example table. Thanks a lot.

 

 

Best!

I think that you want something like:

 

Column = 
VAR __minDate = [date] - 2
VAR __table = FILTER(ALL('Table'),[date]<=EARLIER([date]) && [date]>=__minDate && [store]=EARLIER([store]) && [item]=EARLIER([item]))
VAR __val2day = MAXX(FILTER(__table,[date]=EARLIER([date])-2),[stock qty])
VAR __val1day = MAXX(FILTER(__table,[date]=EARLIER([date])-1),[stock qty])
RETURN
IF(__val2day = [stock qty] && __val1day = [stock qty],1,0)


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.