We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello all,
I am wanting to create a Custom Column in Power Query :
1. I need to count the number of unique items per customer. BUT I dont want to include the items "All Other" or "Both" in the count.
here is an example of the data and the outcome.
| Customer | Items | Customer | Items | Count | ||
| 1 | Plant | 1 | Plant | 2 | ||
| 1 | Cat | 1 | Cat | 2 | ||
| 2 | Dog | 2 | Dog | 1 | ||
| 3 | Car | 3 | Car | 1 | ||
| 4 | Both | 4 | Both | 1 | ||
| 4 | Bottle | 4 | Bottle | 1 | ||
| 5 | All Other | 5 | All Other | 0 | ||
| 6 | Phone | 6 | Phone | 2 | ||
| 6 | Tree | 6 | Tree | 2 |
Is there a good resource I can find info on formulas like this so I dont have to keep asking for help?
Solved! Go to Solution.
try this
Measure =
var _countItems = CALCULATE(DISTINCTCOUNT('Table'[Items]);ALLEXCEPT('Table';'Table'[Customer]);NOT ('Table'[Items] IN ({"Both"; "All Other"})))
RETURN
IF(_countItems < 1; 0; _countItems)
do not hesitate to give a kudo to useful posts and mark solutions as solution
Is it mandatory to use Power Query?
It is a great, easy and very logical task for DAX:
Measure =
var _countItems = CALCULATE(DISTINCTCOUNT('Table'[Items]);ALLEXCEPT('Table';'Table'[Customer]);NOT ('Table'[Items] IN ({"Both"; "All Other"})))
RETURN
IF(SELECTEDVALUE('Table'[Items])="Both" || SELECTEDVALUE('Table'[Items])="All Other";0; _countItems)
do not hesitate to give a kudo to useful posts and mark solutions as solution
@az38 this works perfectly, no requirement to use Power Query.
is there a way I can add a 0 for the two values I am not counting in the formula
thanks for the help
try this
Measure =
var _countItems = CALCULATE(DISTINCTCOUNT('Table'[Items]);ALLEXCEPT('Table';'Table'[Customer]);NOT ('Table'[Items] IN ({"Both"; "All Other"})))
RETURN
IF(_countItems < 1; 0; _countItems)
do not hesitate to give a kudo to useful posts and mark solutions as solution
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 54 | |
| 39 | |
| 32 | |
| 17 | |
| 15 |
| User | Count |
|---|---|
| 64 | |
| 63 | |
| 37 | |
| 34 | |
| 22 |