Forum Discussion

LynnG's avatar
LynnG
Frequent Visitor
3 years ago
Solved

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...
  • Anonymous's avatar
    Anonymous
    3 years ago

    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

     

    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.