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
vanessafvg
Super User
Super User

Best way to dynamically filter date table in Power Query

what is the most efficient way to limit the dates in the date table in power query.

 

I am pulling all my tables from the datawarehouse via sql.  I want to limit the dim date dynamically by only including data for the last 4 years, so that 3 years historical and 1 year ahead because i have a lot of rows in that table.

 

What is the best way to do this?

 

tia!





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

@vanessafvg

 

Hi,

 

There are two ways to do this.

1. Create a view in the Data Warehouse. Then we can connect to the view from Power BI. Maybe it looks like this: 

create view FourYears 
        as select * 
        from daxbook.Date 
        where [Calendar Year Number]<=year(getdate())-4;

2. Edit the query of Power BI in Advanced Editor. Maybe it looks like this:

 

let
    Source = Sql.Database("DB", "contosoretaildw", [Query="select * from daxbook.Date where [Calendar Year Number]<=year(getdate())-4;"])
in
Source

 

Please have a try.

 

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-jiascu-msft
Employee
Employee

Hi @vanessafvg,

 

Could you please mark the proper answer or share your answers if it's convenient for you? That will be a help to others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-jiascu-msft
Employee
Employee

@vanessafvg

 

Hi,

 

There are two ways to do this.

1. Create a view in the Data Warehouse. Then we can connect to the view from Power BI. Maybe it looks like this: 

create view FourYears 
        as select * 
        from daxbook.Date 
        where [Calendar Year Number]<=year(getdate())-4;

2. Edit the query of Power BI in Advanced Editor. Maybe it looks like this:

 

let
    Source = Sql.Database("DB", "contosoretaildw", [Query="select * from daxbook.Date where [Calendar Year Number]<=year(getdate())-4;"])
in
Source

 

Please have a try.

 

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.