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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Distinct count in calculated column

Hi all,

 

Absolute fresher here so please bear with me.

 

I am struggling to understand how to create a calculated column using distinct count - I've managed to find the solution but don't understand why it works.

 

Basically, I wanted to create a calculated column that shows 'unique vendors by product' using the below 'export orders' table

 

timzedel_0-1656253209228.png

 

My initial attempt is as follows:

Unique Vendors by Product = CALCULATE(

DISTINCTCOUNT(export_orders[Vendor]),
export_orders[Product])

This gave me the error message 'cannot convert value 'product1' of type Text to True/False.

 

After some googling, I updated my function to: 

 
Unique Vendors by Product = CALCULATE(
DISTINCTCOUNT(export_orders[Vendor]),
allexcept(export_orders,export_orders[Product]))
 
This gives me the desired calculated column, however, I am confused as to why my initial function did not work - why is 'allexcept' necessary to pull the desired result?
 
 

 

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

When you use calculate ,you need add filter condiction,and like the below(In the dax you started with, less expersion for filtering):

 

CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])

 

 

And if you want to make your first dax work work ,you need to adjust like the below:

 

Unique Vendors by Product3 = CALCULATE(
DISTINCTCOUNT(export_orders[Vendor]),FILTER(ALL(export_orders),
export_orders[Product]=EARLIER(export_orders[Product])))

 

Refer the below output result:

vluwangmsft_0-1656469598644.pngvluwangmsft_1-1656469605050.pngvluwangmsft_2-1656469613770.png

 

And to learn more different between filter and allexcept ,refer the below article ,It is very specific in its presentation:

 
 
 

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


Best Regards

Lucien

View solution in original post

2 REPLIES 2
v-luwang-msft
Community Support
Community Support

Hi @Anonymous ,

When you use calculate ,you need add filter condiction,and like the below(In the dax you started with, less expersion for filtering):

 

CALCULATE(<expression>[, <filter1> [, <filter2> [, …]]])

 

 

And if you want to make your first dax work work ,you need to adjust like the below:

 

Unique Vendors by Product3 = CALCULATE(
DISTINCTCOUNT(export_orders[Vendor]),FILTER(ALL(export_orders),
export_orders[Product]=EARLIER(export_orders[Product])))

 

Refer the below output result:

vluwangmsft_0-1656469598644.pngvluwangmsft_1-1656469605050.pngvluwangmsft_2-1656469613770.png

 

And to learn more different between filter and allexcept ,refer the below article ,It is very specific in its presentation:

 
 
 

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


Best Regards

Lucien

ryan_mayu
Super User
Super User

@Anonymous 

the second parameter of calculate is FILTER, which is  (Optional) Boolean expressions or table expressions that defines filters, or filter modifier functions. e.g. column A=xxx

what you added was the column name. That's why you got the error meassage.

pls see the references below to learn calculate and allexcept

ALLEXCEPT function (DAX) - DAX | Microsoft Docs

CALCULATE function (DAX) - DAX | Microsoft Docs





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

Proud to be a Super User!




Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors