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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Date Filter within Power Query?

I have a report that I need to connect to my SQL sever with a date range for the current year to the end of last month? How would I filter that? I think Power Query would probably be the most intuitive but unaware of any other options?

2 REPLIES 2
TomMartens
Super User
Super User

Hey @Anonymous ,

assuming that the SQL Server tables have date column that enable the filtering you can use this snippet inside each Power Query query to filter the rows of the table accordingly

//creates a datetimevalue that marks the beginning of the current year
    StartOfYear = 
        Date.StartOfYear(
            DateTime.FixedLocalNow()
        )
    //creates a datetimevalue that marks the beginning of the current month    
    , StartOfCurrentMonth = 
        Date.StartOfMonth(
            DateTime.FixedLocalNow()
        )
    //filters the table from the beginning of the current year to the end of previousyear using less than the beginning of the current month     
    , #"Filtered Rows" = 
        Table.SelectRows(
            #"YourTableStep"
            , each [DateKey] >= StartOfYear and [DateKey] < StartOfCurrentMonth
        )

What happens is this:
Two date values are created one, stores the beginning of the current year and the 2nd the beginning of the current month. I consider the condition "less than the start of the current month" more robust finding everything in the previous month because the precision of date/datetime values needs not to be considered.
Then both values are used inside the function Table.SelectRows() to filter the rows of the table accordingly. Here the column of the SQL Server table that contains the date/datetime value is called "DateKey".

Hopefully, this provides what you are looking for to tackle your challenge.

Regards,

Tom
 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Thank you!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.