Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I've searched everywhere for a way to do this. Found a couple of methods that seemed too complex for what I hope is something simple.
I need to apply a dynamic date filter to import SQL queries. Just need to pull in a rolling 12-month period and don't want apply it to views and stored procedures. Is there a simple way to do it in PBI? I created a list table, made a parameter, then filtered the table to >= the parameter. Doesnt' work. Looks like it's due to the Current Value being null.
Any help will be greatly appreciated!
Solved! Go to Solution.
Yes
First, create a new blank query in Power Query. Use this as the formula. This assumes SQL is using a date field.
= Date.AddYears(DateTime.Date(DateTime.LocalNow()), -1)
This will create a scalar value of 10/12/2019 - one year ago. (US Date format - your format might show 19/10/2019 depending on system setttings.)
Then, in your SQL table, filter the date to whatever you want. Doesn't matter. You just want the code to be generated. It might look like this
now you have a Table.SelectRows() that looks like this in the formula bar:
Change it to look like this:
You are getting rid of the date you used to create the filter with varStartDate - which is a dynamically calculated date. It will change every day.
If this is running against a SQL server, this has the added benefit of folding the query, so the server gets this code:
Every time it runs, it will dynamically calculate varStartDate, then will change the native query for SQL Server to use that date. Tomorrow, it would change it to '2019-10-13 00:00:00' and so on.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingYes
First, create a new blank query in Power Query. Use this as the formula. This assumes SQL is using a date field.
= Date.AddYears(DateTime.Date(DateTime.LocalNow()), -1)
This will create a scalar value of 10/12/2019 - one year ago. (US Date format - your format might show 19/10/2019 depending on system setttings.)
Then, in your SQL table, filter the date to whatever you want. Doesn't matter. You just want the code to be generated. It might look like this
now you have a Table.SelectRows() that looks like this in the formula bar:
Change it to look like this:
You are getting rid of the date you used to create the filter with varStartDate - which is a dynamically calculated date. It will change every day.
If this is running against a SQL server, this has the added benefit of folding the query, so the server gets this code:
Every time it runs, it will dynamically calculate varStartDate, then will change the native query for SQL Server to use that date. Tomorrow, it would change it to '2019-10-13 00:00:00' and so on.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingThank you for sharing it.
Could you advise if the query would be still folded in the following scenario?
My date column comes through in a strange format which is not recognized in PowerQuery as date, only as text. So I add a new calculated column to extract the date from that original column and format it as date, and then apply the parameter as a filter in that new, calculated column.
thanks
Perfect! Worked like a charm!! Thank you!!!
Hopefully, someday, implementing date parameters will be easier. 🙂
Agreed! Even here at the end of 2023 Dynamic Paramters are hard to implentment into Import Queries.
Glad to help out @jcampbell474 .
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingStarting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
25 | |
12 | |
11 | |
11 | |
8 |
User | Count |
---|---|
45 | |
28 | |
14 | |
14 | |
13 |