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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
MrBlueSky2
Frequent Visitor

COUNT DISTINCT of expression evaluated at each row

Hi all,

 

I need to count the distinct # of suppliers with products having a lower margin than a field parameter. Assuming the user selects 5% as parameter, I would like to have 2 for suppliers count from the example below (A and C).

SupplierProductMarginCOUNT DISTINCT
A11%A
A22%A
B310% 
C44%C
    
    


As the field parameter is dynamic, I cannot use a calculated column which will only use the default value of the parameter but not update dynamically.

In SQL, I would use something like COUNT DISTINCT (IF margin < parameter then supplier else null)
What DAX formula can I use for similar result?

Thanks in advance for your help

BR

1 ACCEPTED SOLUTION
govind_021
Super User
Super User

Hi @MrBlueSky2 
Please use below code

SuppliersWithLowMarginCount =
VAR LowMarginSuppliers =
CALCULATETABLE(
DISTINCT('Table'[Supplier]),
'Table'[Margin] < [FieldParameter]
)
RETURN
COUNTROWS(LowMarginSuppliers)

Regards
Govind Sapkade ( Data Analyst , Power BI PL 300 Certified , MS Fabric Enthusiast )
Linkdin : www.linkedin.com/in/govind-sapkade-845104225
Youtube : http://www.youtube.com/@govind_dataanalyst




View solution in original post

2 REPLIES 2
govind_021
Super User
Super User

Hi @MrBlueSky2 
Please use below code

SuppliersWithLowMarginCount =
VAR LowMarginSuppliers =
CALCULATETABLE(
DISTINCT('Table'[Supplier]),
'Table'[Margin] < [FieldParameter]
)
RETURN
COUNTROWS(LowMarginSuppliers)

Regards
Govind Sapkade ( Data Analyst , Power BI PL 300 Certified , MS Fabric Enthusiast )
Linkdin : www.linkedin.com/in/govind-sapkade-845104225
Youtube : http://www.youtube.com/@govind_dataanalyst




bhanu_gautam
Super User
Super User

@MrBlueSky2 , Try using

 

dax
SuppliersWithLowMarginCount =
CALCULATE(
COUNTROWS(
DISTINCT('Table'[Supplier])
),
FILTER(
'Table',
'Table'[Margin] < [FieldParameter]
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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