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
bdpaasch
Advocate I
Advocate I

Filter a table by date using DAX - again

Greetings all,

 

Sorry for being stupid, I'm still very new to DAX. Back in 2019 in this community, a question was asked about filtering dates. I think I'm trying to do the same thing, but I'm failing to get the needed result.

Here is the 2019 post: Filter a table by date using DAX 

 

I have a generic date table that I use in various PBI reports (starts in 2019, ends in 2025). I link it to dates fields in various data tables, drop the [date] field into a time slicer and build out my visuals from there. I'm trying to find a good way to limit that generic date table to a date range relevant to whatever report I'm building. For example, we rolled out a new tracking system the day after Christmas this past year (2021). I'd like to constrain the date range for a report that visualizes data from the new system from Dec 26, 2021 through TODAY(). I want my time slicer visual to only offer that range to my report users.

I don't think I care whether I build a new virtual date table and apply dates from the new table to my time slicer, or filter my current date table. Whatever works is fine!

I think I followed the solution provided by @jdbuchanan71 , but it threw an error back at me. (Apologies again, if I weren't so new to DAX, the error message would probably mean something to me and I wouldn't be here!)

 

bdpaasch_0-1646410456633.png

 

Date Range =
CALCULATETABLE(
'date table',
DATESBETWEEN ( 'date table'[date], DATE(2021,12,26), TODAY())
)

 

Seems like this should have been easy, but I'm failing. Thanks for any help!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@bdpaasch the above code is for table not meaure

 

so either create a table

 

to create a measure like

 

countorws(CALCULATETABLE(
'date table',
DATESBETWEEN ( 'date table'[date], DATE(2021,12,26), TODAY())
))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

3 REPLIES 3
bdpaasch
Advocate I
Advocate I

@amitchandak and @johnt75 , thank you both! I like both your answers. @amitchandak , yes, as a new user of DAX, I do still struggle with Measures versus Tables. And yes, copying my code from the measure to a newly created table made a new range-constrained table just like I wanted. @johnt75 , that is clever! I had been fighting with a filter on the slicer visual. I tried Advanced Filtering and selected "is on or after" and put in the Dec 26, 2021 date but when I tried to use the "And" option, there was no obvious way to specify is "is on or before" TODAY. But your idea creates a solution to that problem! Nice.

Now I need to decide who to give the "Accept as Solution" award... Dang, both ideas work and make sense.... @amitchandak , I'm giving it to you since your's was yet another step in my trying to sort out the proper application of measures versus tables. But @johnt75 , I'm probably actually going to use your solution in my current report. Wish I could give it to both of you!

johnt75
Super User
Super User

Add a new column to your date table like

Today or Before = 'Date'[Date] <= TODAY()

then add 2 filters onto the necessary visuals. Firstly, add the date field as a filter and choose Advanced Filtering -> is on or after and put in December 26, 2021.

Secondly, add the new column you created as a filter and only show values where Today or Before is true.

amitchandak
Super User
Super User

@bdpaasch the above code is for table not meaure

 

so either create a table

 

to create a measure like

 

countorws(CALCULATETABLE(
'date table',
DATESBETWEEN ( 'date table'[date], DATE(2021,12,26), TODAY())
))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

November Carousel

Fabric Community Update - November 2024

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

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.