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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Pandadev
Post Prodigy
Post Prodigy

Dax filter required checking change of code by unique ID over a rolling 7 day period

Hi I have 16 million events I need to analyze , to identify when a change of code has taken place for a period of 7 consequative days.

events will not always be daily . Below is a an example , showing events for ID 1

so from 15/4/2023 to 21/4/2023 it has a code of A1

then from 22/04/2023 - 26/04/2023  - 5 days it is changed to B2 , as this is not 7 consequative days it is not flagged as a change

then from 04/05/2023 to 10/05/2023 it is showing as B2 for 7 days , so the max date is flagged as a change

CodeIDDate
A1115/04/2023
A1116/04/2023
A1119/04/2023
A1120/04/2023
A1121/04/2023
B2122/04/2023
B2123/04/2023
B2124/04/2023
B2125/04/2023
B2126/04/2023
A1127/04/2023
A1129/04/2023
A1130/04/2023
B2101/05/2023
A1102/05/2023
A1103/05/2023
B2104/05/2023
B2105/05/2023
B2106/05/2023
B2110/05/2023

 

27 REPLIES 27

How do you plan to calculate the day difference with datetime values? That will get messy quickly.

 

As for the flag - you can do that yourself. Whenever the measure returns 1, and for the previous row it returns 7 or more that is a change flag.

Pandadev
Post Prodigy
Post Prodigy

thanks , that part of the code works great , all I need to do now is create a measure  , that flags when a code has changed please , if I could get the date of the changed code , and the date of previous event before code changed 

so it would flag the following

A1121/04/2023
B2122/04/2023
Pandadev
Post Prodigy
Post Prodigy

A DAX measure please

see above

lbendlin
Super User
Super User

Can you reformulate your requirement to flag all rows where the code has been present for at least 7 consecutive days?

yes that would work , if you could provide me with some example code , I can test it , thanks

Power Query or DAX?  Calculated column or measure?

 

Here is a measure:

 

Consecutive = 
var d = max('Table'[Date])
var c = max('Table'[Code])
var o = calculate(max('Table'[Date]),'Table'[Date]<d,'Table'[Code]<>c)
var n = CALCULATE(min('Table'[Date]),'Table'[Date]>o,'Table'[Code]=c)
return int(d-n+1)

lbendlin_0-1681993837102.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.

Top Solution Authors