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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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