Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
FatBlackCat30
Microsoft Employee
Microsoft 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
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.