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
iqb
Helper III
Helper III

A Calendar Filter with Todays Date Auto Selected

We have reports in Google Data Studio where adding a date filter is as simple as drag and drop but when it comes to Power BI I don't found I data picker filter. 

 

What I am currently doing is adding a new table like,

 

StartDateTableFilter = CALENDAR(TODAY()-1000,TODAY()+1000)

 

and binding this with new parameter called StartDate.

 

I don't find a way to make this date filter to show one date picker UI. Is it possible?

Also, how I make sure to today's date selected by default (instead of date in 2020)?

1 ACCEPTED SOLUTION
jtspilker
Helper I
Helper I

What I've done in the past is create a calculated column in your Date table that shows "Today" for the current date, and the date otherwise. DAX something along the lines of 

 

Selected Date = 
IF( 'Date'[Date] = TODAY(),
   "Today",
   'Date'[Date] & "" --note the concatenation of an empty string onto the Date field so that you have one data type in the column
)

 

You'll then have to bind your parameter to this new calculated column, and use it in your date slicer. Finally, you'll need to modify your power query to use this parameter. Remember, it's now a string, so you'll likely have to convert it to a date in whatever source you're using, and convert the value of "Today" to today's date.

 

For example, I was using SQL as a source, and had to modify my embedded query - one spot of which was updated below:

 

"SELECT [Date] as [DateDQ]#(lf)#(tab),
        cast(case when MonthOfYear > "& Number.ToText(Date.Month(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &" or (MonthofYear = "& Number.ToText(Date.Month(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &" and [DayOfMonth] > "& Number.ToText(Date.Day(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &") then CalendarYear + 1 else CalendarYear end as varchar(4)) end as [Year Scope]

 

 hth

View solution in original post

1 REPLY 1
jtspilker
Helper I
Helper I

What I've done in the past is create a calculated column in your Date table that shows "Today" for the current date, and the date otherwise. DAX something along the lines of 

 

Selected Date = 
IF( 'Date'[Date] = TODAY(),
   "Today",
   'Date'[Date] & "" --note the concatenation of an empty string onto the Date field so that you have one data type in the column
)

 

You'll then have to bind your parameter to this new calculated column, and use it in your date slicer. Finally, you'll need to modify your power query to use this parameter. Remember, it's now a string, so you'll likely have to convert it to a date in whatever source you're using, and convert the value of "Today" to today's date.

 

For example, I was using SQL as a source, and had to modify my embedded query - one spot of which was updated below:

 

"SELECT [Date] as [DateDQ]#(lf)#(tab),
        cast(case when MonthOfYear > "& Number.ToText(Date.Month(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &" or (MonthofYear = "& Number.ToText(Date.Month(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &" and [DayOfMonth] > "& Number.ToText(Date.Day(if ThroughDateParam = "Today" then DateTime.Date(DateTime.LocalNow()) else Date.FromText(ThroughDateParam))) &") then CalendarYear + 1 else CalendarYear end as varchar(4)) end as [Year Scope]

 

 hth

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.