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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
HarryT
Helper I
Helper I

Creating filters for dates - 2 weeks, 1 month, 3 months etc

Hey there,

I am looking to create some date filters.

I would like to create a new table in my calendar with filters I cvan check off to select a date period.

 

ending up like this:

 

Dateview

7 days

14 days

30 days

90 days

180 days

 

I used a tutuorial to get a Yes / No on the current date and thought I could use something simular to create this date filter

 

IsToday =
var currentrowdate = FORMAT('Calendar 2009-2025'[Date].[Date], "mm/dd/yyyy")
var istoday = FORMAT(NOW(), "mm/dd/yyyy")
return
IF(istoday = currentrowdate, "Yes", "No")

 

So what I was thinking was something like (which I know is wrong but you get the idea):

 

DateView =
'Calendar 2009-2025'[Date].[Date],(today()-7))' is '7 Days'
'Calendar 2009-2025'[Date].[Date],(today()-14))' is '14 Days'
'Calendar 2009-2025'[Date].[Date],(today()-30))' is '30 Days'
'Calendar 2009-2025'[Date].[Date],(today()-90))' is '90 Days'
'Calendar 2009-2025'[Date].[Date],(today()-180))' is '180 Days'
 
Is this possible?
Thanks so much.  This would really get me over the hump.

 

1 ACCEPTED SOLUTION

Ok I ended using this instead:

https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

 

I didn't know it existed and it works great!

I appreciate your assistance before.  

View solution in original post

7 REPLIES 7
arneh
Frequent Visitor

Hi,

I'm just thinking out loud...  I added this as a calculated column to my Date Dimension.

 

VAR __RelativeDay__ =
DATEDIFF(TODAY() , 'Date'[Date], DAY )
RETURN
SWITCH( __RelativeDay__,
-7 , "7 Days",
-14 , "14 Days",
-30 , "30 Days",
-90 , "90 Days",
-180, "180 Days"
)

Ok thanks for the qucik reply.

I tried a variation of this by adding a column in my table and got a Syntax error:

 

 

VAR __RelativeDay__ =
DATEDIFF(TODAY() , 'Calendar 2009-2025'[Date].[Date], DAY )
RETURN
SWITCH( __RelativeDay__,
-7 , "7 Days",
-14 , "14 Days",
-30 , "30 Days",
-90 , "90 Days",
-180, "180 Days"
)

 

 

errorsyntax.JPG

arneh
Frequent Visitor

  • Do you have a title ?
CalculatedColumn = 
VAR __RelativeDay__ =
DATEDIFF(TODAY() , 'Calendar 2009-2025'[Date].[Date], DAY )
RETURN
SWITCH( __RelativeDay__,
-7 , "7 Days",
-14 , "14 Days",
-30 , "30 Days",
-90 , "90 Days",
-180, "180 Days"
)

 

Adding on to my ask,

I want to see data in a range of dates.

Like:

 

today-7 , "7 Days",
today-14 , "14 Days",
today-30 , "30 Days",
today-90 , "90 Days",
today-180, "180 Days"

Ok I ended using this instead:

https://docs.microsoft.com/en-us/power-bi/visuals/desktop-slicer-filter-date-range

 

I didn't know it existed and it works great!

I appreciate your assistance before.  

Anonymous
Not applicable

Hey,

I created a calcualted column so that I could use this field as a filter for a card visual I had that showed the number within the past 2 weeks. This may or may not work for your situation; it works for mine as the data is always a day out of date and I look at the most recent period as at date data refreshed.

 

Measure Name =
IF('TABLE'[DATE-FIELD]>=TODAY()-15,1,0)
Replace the above as appropriate (TABLE, DATE-FIELD) with your own table and field
 
Then filter on the '1' value on your visual using this column 🙂
Hope this helps

Yes sorry I just figured that part out.

But this just gives me 14 days ago totals and not 0-14.

I need a range.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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