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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rohit18
Regular Visitor

Count distinct id when the status changes from A to B

Hi all,

wanted to count the distinct Lead_id when it changed it state from qualified to Inactive.

attached image for refrence 

 

rohit18_0-1678265933806.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @rohit18 ,

 

Here I suggest you to try this code to create a measure.

Count = 
VAR _leadid_list =
    CALCULATETABLE (
        VALUES ( 'Table'[lead_id] ),
        FILTER (
            'Table',
            VAR _QualifiedDate =
                CALCULATE (
                    MIN ( 'Table'[date] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[lead_id] ),
                        'Table'[change] = "Qualified"
                    )
                )
            VAR _InactiveDate =
                CALCULATE (
                    MAX ( 'Table'[date] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[lead_id] ),
                        'Table'[change] = "Inactive"
                            && 'Table'[date] > _QualifiedDate
                    )
                )
            RETURN
                _QualifiedDate <> BLANK ()
                    && _InactiveDate <> BLANK ()
        )
    )
RETURN
    COUNTAX ( _leadid_list, [lead_id] )

Result is as below.

RicoZhou_0-1678436596524.png

 

Best Regards,
Rico Zhou

 

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  @rohit18 ,

 

Here I suggest you to try this code to create a measure.

Count = 
VAR _leadid_list =
    CALCULATETABLE (
        VALUES ( 'Table'[lead_id] ),
        FILTER (
            'Table',
            VAR _QualifiedDate =
                CALCULATE (
                    MIN ( 'Table'[date] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[lead_id] ),
                        'Table'[change] = "Qualified"
                    )
                )
            VAR _InactiveDate =
                CALCULATE (
                    MAX ( 'Table'[date] ),
                    FILTER (
                        ALLEXCEPT ( 'Table', 'Table'[lead_id] ),
                        'Table'[change] = "Inactive"
                            && 'Table'[date] > _QualifiedDate
                    )
                )
            RETURN
                _QualifiedDate <> BLANK ()
                    && _InactiveDate <> BLANK ()
        )
    )
RETURN
    COUNTAX ( _leadid_list, [lead_id] )

Result is as below.

RicoZhou_0-1678436596524.png

 

Best Regards,
Rico Zhou

 

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

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.