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
FatBlackCat30
Employee
Employee

D count Column in Power Query

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.

 

CustomerItems  CustomerItemsCount
1Plant  1Plant2
1Cat  1Cat2
2Dog  2Dog1
3Car  3Car1
4Both  4Both1
4Bottle  4Bottle1
5All Other  5All Other0
6Phone  6Phone2
6Tree  6Tree2

 

 

Is there a good resource I can find info on formulas like this so I dont have to keep asking for help?

1 ACCEPTED SOLUTION

@FatBlackCat30 

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

Hi @FatBlackCat30 

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

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@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

@FatBlackCat30 

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

@az38  worked beautifully. thank you for the continued support

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.