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

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

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.