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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

How to rewrite DAX query?

I've created following DAX calculated column with help of variable. I've tried to do the same without variables, but for me using variable is much more simpler.  

Besides is it possible to rewrite following query without variables (I don't need actual query, just yes or no, and which functions should I use)?

CountByMonth = var current_date = 'questions'[Creation Date Dim]
var total = SUMX(FILTER('questions','questions'[Creation Date Dim]=current_date), 'questions'[Count])
return 'questions'[Count] / total

Are there any performance implications, if I'm using variables instead of direct query?

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

@Anonymous

 

Yes you can rewrite without variables.

 

There is a method using CALCULATE and ALLEXCEPT, and another method using FILTER and EARLIER.

 

In general variables avoid repeated evaluation of an expression, but not sure how much that might impact performance in this case - others may have an idea.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

Baskar
Resident Rockstar
Resident Rockstar

hey , 

 

Var plays the main important role in DAX. It is Super Hero of Dax. It will cant give performance issue comapre with anyother DAX Functions like Earlier etc ..

 

I stongly suggest use VAR  

View solution in original post

2 REPLIES 2
Baskar
Resident Rockstar
Resident Rockstar

hey , 

 

Var plays the main important role in DAX. It is Super Hero of Dax. It will cant give performance issue comapre with anyother DAX Functions like Earlier etc ..

 

I stongly suggest use VAR  

OwenAuger
Super User
Super User

@Anonymous

 

Yes you can rewrite without variables.

 

There is a method using CALCULATE and ALLEXCEPT, and another method using FILTER and EARLIER.

 

In general variables avoid repeated evaluation of an expression, but not sure how much that might impact performance in this case - others may have an idea.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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