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
Anonymous
Not applicable

Count distinct items that have a specific value in another column but have ALSO had another value

I haven't found this in a search so maybe I'm asking it wrong or thinking about it incorrectly.  I have a data set with 2 columns (simplified) and I want to count the number of "Items" (rows) that have a specific value in the "Sprint" column, but ONLY count it if that "Item number" ALSO has a different value in the "Sprint" column.  Here is a simplified dataset

Item NumberSprint
1061511Backlog
1061511Sprint 23
1061511Sprint 24
1061511Sprint 25
1061511Sprint 26
1104217Sprint 22
1104217Sprint 23
1210684Backlog
1210684Sprint 24
1210685Sprint 25

 

The logic seem to me:  Count "Item Number", if it's Sprint value is "Sprint 25" BUT ONLY if "Item number" also has a value that is NOT "Sprint 25" and is also not "Backlog".   My count should be 2.  Item number 1061511 and 1210685 meet the criteria, 1104217 never has a "Sprint 15" value so it isn't counted.

 

Hope this did not double post - hit POST the last time I typed it up but it didn't seem to go through.
Any help is appreciated

3 REPLIES 3
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Please check if the attachment is helpful.

Count =
VAR SelectedSprint =
    SELECTEDVALUE ( 'Table'[Sprint] )
VAR CurrentSprint =
    MAX ( 'Table'[Sprint] )
VAR t =
    ADDCOLUMNS (
        'Table',
        "Sprint_",
            IF (
                COUNTROWS (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Item Number] = EARLIER ( 'Table'[Item Number] )
                            && 'Table'[Sprint] = SelectedSprint
                    )
                ) = 1
                    && COUNTROWS (
                        FILTER (
                            ALL ( 'Table' ),
                            'Table'[Item Number] = EARLIER ( 'Table'[Item Number] )
                                && 'Table'[Sprint] <> "Backlog"
                                && 'Table'[Sprint] <> SelectedSprint
                        )
                    ) >= 1,
                1
            )
    )
RETURN
    COUNTROWS ( FILTER ( t, [Sprint_] = 1 ) )

 

 

Best regards

Icey

 

If this post helps,then consider Accepting it as the solution to help other members find it faster.

 

Anonymous
Not applicable

Thank you for the reply.  It is currently not working and showing a "blank".
When I try each individual filter in the "IF" statement I get "EARLIER/EARLIEST refers to an earlier row context which doesn't exist."  So I will continue to tweak it and see if I can get it to work.

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Is this problem solved?

 

If it is solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If not, please share your .pbix, removing sensitive information, for test.

count.gif

 

Best Regards,

Icey

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.