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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
LynnG
Frequent Visitor

Please Help! For each Serial Number i need to count the days its consecutively Active

 

Using PowerBi Live Connection - I have a serial number field and 1 date field.

I need a measure that calculates the number of days a unit (Serial Number) is Active for a concecutive number of days. I am using a Live Connection so I cant just do it in a local desktop table. So for the first serial number on 1/1 it was Active for 1 day and counts up until a day is missed, then starts over again for each change in serial number.

So for Each serial number, sort by date to calculate how many days it has been consecutively active and then re-start the count. (If it is listed then it is Active.)

 

 

Serial Numbersummary_dateconsecutive days
ABXM6U167361/1/20231
ABXM6U167361/2/20232
ABXM6U167361/3/20233
ABXM6U167361/4/20234
ABXM6U167361/6/20231
ABXM6U167361/7/20232
ABXM6U167361/8/20233
ABXM6U167361/9/20234
ABXM6U167361/10/20235
ABXM6U167361/11/20236
ABXM6U167361/12/20237
ABXM6U166861/1/20231
ABXM6U166861/2/20232
ABXM6U166861/3/20233
ABXM6U166861/7/20231
ABXM6U166861/8/20232
ABXM6U166861/10/20231
ABXM6U166861/11/20232
ABXM6U166861/12/20233
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @LynnG ,

I have created a simple sample, please refer to it to see if it helps you.

Create measures.

flag =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[summary_date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Serial Number] ),
            [summary_date] < MAX ( 'Table'[summary_date] )
        )
    )
VAR _b =
    MAX ( 'Table'[summary_date] ) - 1
RETURN
    IF ( _a <> _b, 0, 1 )
minflagdate = 
CALCULATE (
    MAX ( 'Table'[summary_date] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[summary_date] <= SELECTEDVALUE ( 'Table'[summary_date] )
            && [flag] = 0
            && 'Table'[Serial Number] = SELECTEDVALUE ( 'Table'[Serial Number] )
    )
)
result = DATEDIFF([minflagdate],MAX('Table'[summary_date]),DAY)+1

 

vpollymsft_0-1675220869988.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

2 REPLIES 2
Anonymous
Not applicable

Hi @LynnG ,

I have created a simple sample, please refer to it to see if it helps you.

Create measures.

flag =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[summary_date] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Serial Number] ),
            [summary_date] < MAX ( 'Table'[summary_date] )
        )
    )
VAR _b =
    MAX ( 'Table'[summary_date] ) - 1
RETURN
    IF ( _a <> _b, 0, 1 )
minflagdate = 
CALCULATE (
    MAX ( 'Table'[summary_date] ),
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[summary_date] <= SELECTEDVALUE ( 'Table'[summary_date] )
            && [flag] = 0
            && 'Table'[Serial Number] = SELECTEDVALUE ( 'Table'[Serial Number] )
    )
)
result = DATEDIFF([minflagdate],MAX('Table'[summary_date]),DAY)+1

 

vpollymsft_0-1675220869988.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

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

Thank you so much!! This worked perfectly!!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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