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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-rzhou-msft
Community Support
Community Support

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
v-rzhou-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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