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

i need to use bookmarks that can save filters like year to date etc with filters to pass Sql

I need to pass datetable with a column bind to startdate parameter and passed to sql query in direct mode like 

select a,max(b)b,max(c)c,max(ac)ac,max(dt)dt from tabl1 

join (select ac,max(c) from tabl2 group by ac)tabs on tabl1.ac= tabl2.ac

where dt between @datefrom and @dateto
group by a
i'm create 2 calander date tables and 2 parameters start date and end date, and biniding table colmns to these parameters and passing them in query editor in m script - thats is cool!
now i want to create a bookmarks for 

  • Year-to-Date
  • Last Year
  • Last Quarter
  • As of Today
    how to acheive that as realtive date is missing see below
  •  Asmasm_0-1731089217782.png
4 REPLIES 4
Asmasm
Helper I
Helper I

Any help will be appriciated! @rajendraongole1 @Ritaf1983  @lbendlin 

Asmasm
Helper I
Helper I

I have added datefrom and dateto variable so that I can pass value from power bi to sql query

Asmasm
Helper I
Helper I

Thanks for ur response! But we don't have relative date option available. Additionally we are passing dates on sql query then using group by. Means my filter is applicable on query level not power bi level, there the current method will give wrong results. As we are getting max of dt in above query, there could be multiple dates but at power bi we are getting max of it. Any other alternative plz Im bagging my head

rajendraongole1
Super User
Super User

Hi @Asmasm -you can achieve dynamic date range filtering (e.g., Year-to-Date, Last Year, Last Quarter, As of Today) by creating measures with dynamic date calculations instead of relying solely on parameters. 

 

Create a disconnected table with the name Date Range Selection that contains your date range options:

DateRangeOptions =
DATATABLE(
"Date Range", STRING,
{
{"Year-to-Date"},
{"Last Year"},
{"Last Quarter"},
{"As of Today"}
}
)

 

rajendraongole1_0-1731135970667.png

 

Now, Create a new measure to display the filtered data based on the selected date range option

DynamicSales =
SWITCH(
SELECTEDVALUE('DateRangeOptions'[Date Range]),
"Year-to-Date", [Sales_YTD],
"Last Year", [Sales_LastYear],
"Last Quarter", [Sales_LastQuarter],
"As of Today", [Sales_AsOfToday],
BLANK()
)

 

For each date range option, select the corresponding value in the Date Range Selection slicer.
Go to the View tab > Bookmarks and add a new bookmark for each selection (e.g., YTD, Last Year, Last Quarter, As of Today).

 

Add buttons to your report (e.g., for Year-to-Date, Last Year, Last Quarter, As of Today).
Set the Action property of each button to the corresponding bookmark, so users can switch between date ranges by clicking the buttons.

 

Or 

If you’re working within Power BI Service or Power BI Desktop with an active connection, you could also explore using the Relative Date Slicer.

 

rajendraongole1_1-1731136037690.png

 

Hope this works.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.