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
jessset
Helper I
Helper I

Slow DAX Measure when Adding to Filter

Hi All,


I have a matrix table like below:

 
Account NumberAmount (Measure)Benchmarked Amount (Measure)
Account 1$$$$$$
Account 2$$$$$$
Account 3$$4$$$

 

The Account Number maps to a table like below:

Account NumberStart DateEnd Date
Account 11 Jan 199931 Dec 2099
Account 21 Jan 199931 March 2019
Account 31 April 201931 Dec 2099

 

I then have a slicer which allows the user to select a date. When a date is selected, I want to to filter out accounts which are not in between the [Start Date] and [End Date], but with additional criteria. So I have created a measure as below:

 

Account Filter =
var SelectedDate = MAX('Calendar'[Date])
RETURN
SWITCH(SELECTEDVALUE(Slicer_Period[Period]),
"MTD", IF(DATEDIFF(SelectedDate,MAX(Accounts[End Date]),DAY)<-31,"Y",""),
IF(DATEDIFF(SelectedDate,MAX(Accounts[End Date]),DAY)<-365,"Y",""))

 

Before I added this measure to the Filter on this Visual, it runs fairly quickly. But when I added the above measure into the filter (where [Account Filter] is "Y"), it becomes very slow.

Any ideas on how to make this quicker (filtering out rows based on a measure)?

Thanks in advance!

6 REPLIES 6
jessset
Helper I
Helper I

Thanks Guys!

 

But none of the suggested solutions seem to make things quicker... Have a feeling there are too many measures already in place.

@jessset I don't suppose you can share the PBIX?

@ 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...
amitchandak
Super User
Super User

@jessset , Try like

Account Filter =
var _max = MAXX(allselected('Calendar'),'Calendar'[Date])
var SelectedDate = DATEDIFF(_max,MAX(Accounts[End Date]),DAY)
RETURN
SWITCH(SELECTEDVALUE(Slicer_Period[Period]),
"MTD", IF(SelectedDate<-31,"Y",""),
IF(DATEDIFF(SelectedDate<-365,"Y",""))
)

Greg_Deckler
Super User
Super User

@jessset OK, a couple things to try. One would be this:

 

Account Filter =
var SelectedDate = MAX('Calendar'[Date])
RETURN
SWITCH(SELECTEDVALUE(Slicer_Period[Period]),
"MTD", IF( (SelectedDate - MAX(Accounts[End Date])) * 1. <-31,"Y",""),
IF( (SelectedDate - MAX(Accounts[End Date])) * 1. <-365,"Y",""))

Another possible variation:

Account Filter =
var SelectedDate = MAX('Calendar'[Date])
RETURN
SWITCH(SELECTEDVALUE(Slicer_Period[Period]),
"MTD", IF(DATEDIFF(SelectedDate,MAX(Accounts[End Date]),DAY)<-31,1,0),
IF(DATEDIFF(SelectedDate,MAX(Accounts[End Date]),DAY)<-365,1,0))

You could combine these approaches

 

Trying to think of ways to leverage pre-filtering but not thinking of any off the top of my head. Curious, how many accounts are there unfiltered in the visual?

 

The general technique you are using I just posted about. https://community.powerbi.com/t5/Quick-Measures-Gallery/The-Complex-Selector/td-p/1116633

 


@ 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...
Greg_Deckler
Super User
Super User

@jessset Perhaps try explaining the problem you are trying to solve and there may be a better way of going about it. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ 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...

Thanks Greg, hopefully the revised post above helps!

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.

Top Solution Authors