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 August 31st. Request your voucher.
I am trying to work if it is possible to do some caluclations without the needing multiple measures.
For example if I have 2 measures like this:
Measure1 = CALCULATE(DISTINCTCOUNT('Table'[field1]),FILTER('Table',not(ISBLANK('Table'[field1]))))
Measure2 = CALCULATE(DISTINCTCOUNT('Table'[field2]),FILTER('Table',not(ISBLANK('Table'[field2]))))
And I need to add the total of these 2 measures together (Measure1 + Measure2). I know I can create a third measure to achieve this, but my question is is there a way to complete the above calculation in a single measure rather than needing to create 3, since it seems a little unnecessarily messy?
Solved! Go to Solution.
Yes, a single DAX measure can include multiple calculations like CALCULATE, FILTER, DISTINCTCOUNT, and arithmetic operations. You don't need separate measures if you're only using them once. You can combine the logic directly into one measure to keep things cleaner and more efficient using variable
Like this
Measure=
CALCULATE(
DISTINCTCOUNT('Table'[field1]),
FILTER('Table', NOT(ISBLANK('Table'[field1])))
)
+
CALCULATE(
DISTINCTCOUNT('Table'[field2]),
FILTER('Table', NOT(ISBLANK('Table'[field2])))
)
Thanks
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
Hi @PowerAutomater ,
Thank you for reaching out. @pankajnamekar25 & @Jihwan_Kim has provided a response that matches your requirement. Please review and try the suggested solution.
If you need any additional information or further assistance, please let us know. we are ready to help.
Thank you for your valuable insight's @Jihwan_Kim , @pankajnamekar25 .
— Yugandhar
Community Support Team.
Yes, a single DAX measure can include multiple calculations like CALCULATE, FILTER, DISTINCTCOUNT, and arithmetic operations. You don't need separate measures if you're only using them once. You can combine the logic directly into one measure to keep things cleaner and more efficient using variable
Like this
Measure=
CALCULATE(
DISTINCTCOUNT('Table'[field1]),
FILTER('Table', NOT(ISBLANK('Table'[field1])))
)
+
CALCULATE(
DISTINCTCOUNT('Table'[field2]),
FILTER('Table', NOT(ISBLANK('Table'[field2])))
)
Thanks
If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.
Hi,
Please try something like below.
expected result measure: =
VAR _Measure1 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[field1] ),
FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[field1] ) ) )
)
VAR _Measure2 =
CALCULATE (
DISTINCTCOUNT ( 'Table'[field2] ),
FILTER ( 'Table', NOT ( ISBLANK ( 'Table'[field2] ) ) )
)
RETURN
_Measure1 + _Measure2
User | Count |
---|---|
80 | |
74 | |
41 | |
30 | |
28 |
User | Count |
---|---|
107 | |
96 | |
53 | |
47 | |
47 |