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
ARomain
Helper I
Helper I

Distinct Count of Cases Based on Multiple Rows Dispositions

I am trying to distinct count the number of IDs that did not ship any item. It doesn't matter what the item was, just if an ID had ANY item that shipped or did not ship.

 

In my exmaple below, IDs 3 and 4 did not ship any item, so I am trying to figure out a measure that would bring back a result of 2 but I can't wrap my head around a measure. 

 

 

 

ARomain_0-1642109006044.png

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You could iterate through the ID values and check if there is exactly one distinct disposition equal to Not Shipped.

 

COUNTROWS (
    FILTER (
        VALUES ( Table1[ID] ),
        CALCULATE ( SELECTEDVALUE ( Table1[Disposition] ) ) = "Not Shipped"
    )
)

 

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

You could iterate through the ID values and check if there is exactly one distinct disposition equal to Not Shipped.

 

COUNTROWS (
    FILTER (
        VALUES ( Table1[ID] ),
        CALCULATE ( SELECTEDVALUE ( Table1[Disposition] ) ) = "Not Shipped"
    )
)

 

That is a very elegant solution @AlexisOlson !



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
freginier
Solution Specialist
Solution Specialist

Create a flag column to check if an ID has been shipped if true then 0 and 1 if never shipped.

Flag = 
VAR Total_shipped =
    CALCULATE ( count ( Table2[ID] ), FILTER( Table2, EARLIER(Table2[ID])=Table2[ID] ), Table2[Disposed]="Shipped" )
RETURN
    IF ( Total_shipped > 0, 0, 1 )

 Create a measure and count the ID never shipped (flag = 1)

Measure = CALCULATE( DISTINCTCOUNT( Table2[ID] ), Table2[Flag] = 1)

 

bcdobbs
Super User
Super User

I think this works.  I called the table Shipping:

IDs Not Shipped = 

VAR ShippedIds = 
    CALCULATETABLE(
        VALUES ( Shipping[ID] ),
        Shipping[Disposition] <> "Not Shipped"
    )

VAR NotShippedIds = 
    CALCULATETABLE (
        VALUES ( Shipping[ID] ),
        Shipping[Disposition] = "Not Shipped"
    )

VAR NeverShippedIds =
    EXCEPT( NotShippedIds, ShippedIds )

RETURN
    COUNTROWS ( NeverShippedIds )


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

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.