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.
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!!
Solved! Go to Solution.
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!
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!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
100 | |
78 | |
76 | |
52 |
User | Count |
---|---|
144 | |
109 | |
108 | |
88 | |
61 |