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
iplaygod
Resolver I
Resolver I

DAX: How can I exclude user ids found in one measure from the other measure?

Hi!

 

I am doing stats on sales. And I have a table containing sales and user ids.
I want to enforce a rule that excludes any User IDs found in measure 1 from measure 2.

table looks something like this:

Date        User ID    Product     Discount
---------------------------------------------------------
2018-11-01    1    shoe A        yes
2018-11-02    1    shoe B        no
2018-11-03    1    shoe C        yes
2018-11-04    2    shoe A        no
2018-11-05    3    shoe A        no
2018-11-06    4    shoe A        yes
2018-11-07    5    shoe A        yes
2018-11-08    6    shoe A        no
2018-11-09    7    shoe A        yes
2018-11-10    8    shoe A        no

I want to count distinct user ids found during a certain period.

I want to create 2 measures:

[Users purchased with discount]

and

[Users purchased without discount]


However, the problem is that in some cases, users appear in both.
User ID = 1 has purchased both WITH and WITHOUT a discount.

And so this user will be counted in both measures.
And if I add the two measures together, the total number of users will be inflated, because one user will count in both.
I want to enforce a rule that excludes any User IDs found in measure 1 from measure 2.

 

I think I should be able to do this by extracting the user ids from measure 1 and then using a NOT IN clause in measure two.

But currently I have no idea how to actually achieve this.

 

Please give me some example code.

Thanks!!

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

Try like this: 

 

CALCULATE(
    DISTINCTCOUNT( Sales[User ID] ),
    Sales[ Discount] = "no",
    NOT Sales[User ID] IN 
        CALCULATETABLE( VALUES( Sales[User ID] ), Sales[ Discount] = "yes" )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

2 REPLIES 2
LivioLanzo
Solution Sage
Solution Sage

Try like this: 

 

CALCULATE(
    DISTINCTCOUNT( Sales[User ID] ),
    Sales[ Discount] = "no",
    NOT Sales[User ID] IN 
        CALCULATETABLE( VALUES( Sales[User ID] ), Sales[ Discount] = "yes" )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

thanks @LivioLanzo for quick reply!
I will try it and get back!

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.