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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Combining Multiple DAX Measures - how to do it?

Hi - I have a couple of measures that I compare against each other to get another measure - I'd like to be able to put all 3 of them into one longer DAX measure, is that possible?? Is there a more elegant way of doing everything in one? I have:

 

WEEK 31 Total Products =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

 

and


WEEK 31 Out of Stock =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[OOS] = 1),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

 

which I then use to get


WEEK 31 AVAILABILITY =
1 - DIVIDE(('Combined_GPI'[WEEK 31 Out of Stock]), ('Combined_GPI'[WEEK 31 Total Products]))

 

Any help greatly appreciated!

Dan 🙂

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Anonymous Try:

WEEK 31 AVAILABILITY =

VAR __WEEK31TotalProducts =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

VAR __WEEK31OutofStock =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[OOS] = 1),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

RETURN
  1 - DIVIDE(('Combined_GPI'[__WEEK31OutofStock]), ('Combined_GPI'[__WEEK31TotalProducts]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous Try:

WEEK 31 AVAILABILITY =

VAR __WEEK31TotalProducts =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

VAR __WEEK31OutofStock =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[OOS] = 1),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

RETURN
  1 - DIVIDE(('Combined_GPI'[__WEEK31OutofStock]), ('Combined_GPI'[__WEEK31TotalProducts]))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks @Greg_Deckler  - thats super helpful! I'll do some learning on Variables 🙂

goncalogeraldes
Super User
Super User

Hi there! In this case you can make use of variables inside of a single measure. For example, in your case ot could be:

WEEK 31 AVAILABILITY =
var WEEK_31_Total_Products =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

var WEEK_31_Out_of_Stock =
CALCULATE(
COUNTROWS ('Combined_GPI'),
FILTER('Combined_GPI','Combined_GPI'[OOS] = 1),
FILTER('Combined_GPI','Combined_GPI'[Week] = 31)
)

return 
CALCULATE(
1 - DIVIDE(WEEK_31_Out_of_Stock, WEEK_31_Total_Products)
)

 

Hope this solves your problem! If you need additional help please tag me in your reply.
If my reply provided you with a solution, pleased mark it as a solution ✔️ or give it a kudoe 👍
Thanks!

Best regards,
Gonçalo Geraldes

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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