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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Filter measure dates relative to date slicer

I want to filter my measure dates based on a date slider that's on the same page.

I want a measure to get dates starting day before period that is selected with slicer.

 

For example if I have the following slider on the report page...

PBIDesktop_2017-12-19_14-14-04.png

 

 ...the measure would get rows between dates 31.12.2016-18.7.2017; starting 1 day earlier than the slicer.

So if I create a table with the measure it would include rows starting from 31.12.2016 and ending to 18.7.2017

 

Any tips how I could achieve this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@Anonymous,

Create measue using dax below.

Measure = VAR minDate = MIN('Final data'[Event Date])-1

VAR MaxDate = MAX('Final data'[Event Date])
RETURN
    CALCULATE(SUM('Final data'[Number of persons]),DATESBETWEEN('Final data'[Event Date],minDate,MaxDate))

1.JPG2.JPG

Regards,
Lydia

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

@Anonymous,

Create measue using dax below.

Measure = VAR minDate = MIN('Final data'[Event Date])-1

VAR MaxDate = MAX('Final data'[Event Date])
RETURN
    CALCULATE(SUM('Final data'[Number of persons]),DATESBETWEEN('Final data'[Event Date],minDate,MaxDate))

1.JPG2.JPG

Regards,
Lydia

Anonymous
Not applicable

Thank you, that works wonders!

is it possible to set the same date slicer to a default value?

Greg_Deckler
Community Champion
Community Champion

If you date slicer is tied to a separate Calendar table, then you could always just get the MIN and MAX of that table and do a DATEADD, something like:

 

m_Measure = CALCULATE(SUM(Table[Column]),FILTER(Table,[Date]>=DATEADD(MIN(Calendar[Date]),-1,day) && Table[Date]<=MAX(Calendar[Date]))

Something like that. 



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!:
DAX For Humans

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

Thank you for your reply.

I have a separate calendar table and tried your method but it gives an error:

 A function 'MIN' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

That's kind of strange. Try this:

 

m_Measure = VAR myMin = DATEADD(MIN(Calendar[Date]),-1,day)
VAR myMax = MAX(Calendar[Date]
RETURN
 CALCULATE(SUM(Table[Column]),FILTER(Table,[Date]>=myMin && Table[Date]<=myMax))


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!:
DAX For Humans

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

Giving the same error about the MIN on the first row.

 

I'm trying this with a simple dataset containing a 'Calendar' table which contains 'Date' and table 'Final data' which has two columns: 'Event Date' and 'Number or persons'.

 

Just to be sure I'm not messing something up here's the method:

 

m_Measure = VAR myMin = DATEADD(MIN(Calendar[Date]);-1;day)
VAR myMax = MAX(Calendar[Date])
RETURN
    CALCULATE(SUM('Final data'[Number of persons]);FILTER('Final data';[Event Date]>=myMin && 'Final data'[Event Date]<=myMax))

 

That's a really weird error for that. Try this:

 

m_Measure = VAR myDate = MIN(Calendar[Date])
VAR myMin = DATEADD(myDate;-1;day)
VAR myMax = MAX(Calendar[Date])
RETURN
    CALCULATE(SUM('Final data'[Number of persons]);FILTER('Final data';[Event Date]>=myMin && 'Final data'[Event Date]<=myMax))


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!:
DAX For Humans

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

That gives:

"The first argument to 'DATEADD' must specify a column."

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.