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

Distinct count of values from group A that do not exist in group B

Hi Everyone!

 

I'm struggling a long time with the following issue: 

I have 2 groups of items that I calculated - > A and B.

I need to count all distinct values from Group B that do not exist in group A -> Group C.

The following query will demonstrate it:

 

New group - C =
VAR A =
CALCULATE(VALUES(order[Material_Number]),
FILTER(order,order[Upsale_Amount]=0)
)

VAR  B =
CALCULATE(VALUES(order[Material_Number]),
FILTER(order,order[Upsale_Amount]>=1))
 
VAR C = IF(VALUE(UpSale_Items)=VALUE(Origin_Items),0,1)
return C
 
The last part of the query (var c) causing the issue.
When I add the measure to a table it says that the query returns multiple values instead of one. 
 
Anyone has any idea how to solve it?
1 ACCEPTED SOLUTION

@Anonymous 

Please try now, I didn't test it, 

New group Measure =
VAR A = CALCULATETABLE (VALUES(order[Material_Number]),  order[Upsale_Amount] = 0)
VAR B = CALCULATETABLE (VALUES(order[Material_Number]), order[Upsale_Amount] >=1)
VAR C =  COUNTROWS( DISTINCT ( EXCEPT ( A , B ) ) )
RETURN
C

Switch A and B within EXCEPT if you don't get the results. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
Fowmy
Super User
Super User

@Anonymous 

Not sure if you need a new table or measure, 

For distinct count measure use the following:

New group Measure =
VAR A = CALCULATETABLE (VALUES(order[Material_Number]),  order[Upsale_Amount] = 0)
VAR B = CALCULATETABLE (VALUES(order[Material_Number]), order[Upsale_Amount] >=1)
VAR C =  DISTINCTCOUNT ( EXCEPT ( A , B ) )


For Table:

New group Table =
VAR A = CALCULATETABLE (VALUES(order[Material_Number]),  order[Upsale_Amount] = 0)
VAR B = CALCULATETABLE (VALUES(order[Material_Number]), order[Upsale_Amount] >=1)
VAR C =  EXCEPT ( A , B )
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Hi Fowmy!

 

Thanks for your response. 

I tried the measure you created but the last line of the query returns an error. 

 

KatyaK_1-1633328255967.png

 

 

@Anonymous 
If you need a measure, you need to use the first code block that I shared, for the table, you the 2nd one

Fowmy_0-1633329388942.png

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Yeh I know, what I'm tring to say that I get an error in the syntax of the measure. 

It doesn't let me to use distinctcount - as showcased in the image I added in my previous answer. 

@Anonymous 

Please try now, I didn't test it, 

New group Measure =
VAR A = CALCULATETABLE (VALUES(order[Material_Number]),  order[Upsale_Amount] = 0)
VAR B = CALCULATETABLE (VALUES(order[Material_Number]), order[Upsale_Amount] >=1)
VAR C =  COUNTROWS( DISTINCT ( EXCEPT ( A , B ) ) )
RETURN
C

Switch A and B within EXCEPT if you don't get the results. 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

Thanks a lot it works!!

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.