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

Counting days between a change

Hi there,


I have measures for Percent, and Percent previous day. I also have a measure to flag if the daily change went up or down. 

What I am wanting to do is write a measure that counts the number of days between the start of each change, as shown in the image. 

Can you please assist me in helping to write this measure? Thanks. 

 

percentchange.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @greenskmachine2 ,

 

Check the following measure:

Consecutive Days Measure = 
VAR CurrentDate = MAX('Table'[Date])
VAR CurrentFlag = MAX('Table'[Percent Change Flag])

VAR PreviousDates =
    FILTER(
        ALL('Table'),
        'Table'[Date] < CurrentDate
    )

VAR LastChangeDate =
    MAXX(
        FILTER(
            PreviousDates,
            'Table'[Percent Change Flag] <> CurrentFlag
        ),
        'Table'[Date]
    )

VAR StartDate =
    IF(ISBLANK(LastChangeDate), MIN('Table'[Date]), LastChangeDate)

VAR ConsecutiveDays =
    DATEDIFF(StartDate, CurrentDate, DAY)

RETURN
IF(NOT ISBLANK(CurrentFlag), ConsecutiveDays, BLANK())

Result:

vyajiewanmsft_0-1733899584556.png

Best regards,

Joyce

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @greenskmachine2 ,

 

Check the following measure:

Consecutive Days Measure = 
VAR CurrentDate = MAX('Table'[Date])
VAR CurrentFlag = MAX('Table'[Percent Change Flag])

VAR PreviousDates =
    FILTER(
        ALL('Table'),
        'Table'[Date] < CurrentDate
    )

VAR LastChangeDate =
    MAXX(
        FILTER(
            PreviousDates,
            'Table'[Percent Change Flag] <> CurrentFlag
        ),
        'Table'[Date]
    )

VAR StartDate =
    IF(ISBLANK(LastChangeDate), MIN('Table'[Date]), LastChangeDate)

VAR ConsecutiveDays =
    DATEDIFF(StartDate, CurrentDate, DAY)

RETURN
IF(NOT ISBLANK(CurrentFlag), ConsecutiveDays, BLANK())

Result:

vyajiewanmsft_0-1733899584556.png

Best regards,

Joyce

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.