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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
denpries
Resolver I
Resolver I

Which dax statement is more efficient?

 

Dear users.

 

I was wondering, while building a piece of DAX, if i could improve it or not. Below is a formula i use to calculate the sales in period 1, starting at P1 start and ending at P1 end.

 

P1 Sales = CALCULATE([Sales];DATESBETWEEN(DateTable[Dates];[P1 start];[P1 end]))

 

 

The second argument might lead to a table of e.g. 365 rows, if i have P1 start at Januari 1st, and P1 end at December 31st.

 

As i know the sales table ALWAYS ONLY has sales at the 1st of the month, i thought, why not have the second argument filtered?

Sales is a table of 500k rows by the way. 

 

P1 Sales* = CALCULATE([Sales];filter(DATESBETWEEN(DateTable[Datum];[P1 start];[P1 end]);day(DateTable[Datum])=1))

 

or:

P1 Sales* = CALCULATE([Sales];DATESBETWEEN(DateTable[Datum];[P1 start];[P1 end]);day(DateTable[Datum])=1)

 

So this way i pass as filter to CALCULATE only 12 days, namely the 1st day of every month. 

 

Would this speed matters up? Or is this hypothetical BS and do i just creat more overhead? 😛

 

 

1 ACCEPTED SOLUTION

@denpries,

In your original post, the P1 Sales* will be more efficient than P1 Sales, and it executes faster than P1 Sales. The DAX Greg_Deckler provides will spend more time to execute comparing with your original measures.

You can use SQL Server Profiler to check the query duration and DAX query plan for these measures and verify the whole process. There are some blogs for your reference.
https://insightsquest.com/2017/05/07/profiler-trace-for-power-bi-desktop/
https://www.sqlbi.com/wp-content/uploads/DAX-Query-Plans.pdf

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

Perhaps:

 

P1 Sales = 
VAR tmpDates = FILTER(FILTER(DateTable,DAY([Dates])=1),[Dates]>=[P1 start] && [Dates]<=[P1 end)
RETURN SUMX(tmpDates,[Sales])


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

 

@Greg_Deckler that also works, yes. If i understand it correctly you filter from the dates table all applicable rows (so basically 1 per month) and then sumx evaluates the [sales] for every row of that table and adds it together.

What i dont understand yet, and try to know why, if this approach is more efficient then the other.

 

Anybody else with an opinion about this / some more in depth knowledge?

@denpries,

In your original post, the P1 Sales* will be more efficient than P1 Sales, and it executes faster than P1 Sales. The DAX Greg_Deckler provides will spend more time to execute comparing with your original measures.

You can use SQL Server Profiler to check the query duration and DAX query plan for these measures and verify the whole process. There are some blogs for your reference.
https://insightsquest.com/2017/05/07/profiler-trace-for-power-bi-desktop/
https://www.sqlbi.com/wp-content/uploads/DAX-Query-Plans.pdf

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much for your excellent links, as well as your answer

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.