The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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).
Supplier | Product | Margin | COUNT DISTINCT |
A | 1 | 1% | A |
A | 2 | 2% | A |
B | 3 | 10% | |
C | 4 | 4% | 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
Solved! Go to Solution.
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
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
@MrBlueSky2 , Try using
dax
SuppliersWithLowMarginCount =
CALCULATE(
COUNTROWS(
DISTINCT('Table'[Supplier])
),
FILTER(
'Table',
'Table'[Margin] < [FieldParameter]
)
)
Proud to be a Super User! |
|
User | Count |
---|---|
15 | |
13 | |
8 | |
6 | |
6 |
User | Count |
---|---|
24 | |
19 | |
12 | |
9 | |
7 |