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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Date Manipulation

I'm trying to create a query that references a previous query but removes the last 3 days worth of contents.

Although I could just run another SQL query to do this, I thought it may be more efficient to use truncate the already obtained data.

 

However, it's not been as simple as it seems.

 

There is no relative terminology that I could find in M Query, so I've gone down the lines of adding a conditional column.

[Date] = Date.AddDays(Date.From(DateTime.LocalNow), -3)

 

I seem to struggle with date manipulation in Power BI - there are so many built-in functions, but not all of them play well together.

 

I'd appreciate any pointers or help you can give.

 

 

Thanks,

 

Chris

1 ACCEPTED SOLUTION

That would work too, or you could just add "not" to what I sent before

 

=Table.SelectRows(#"Changed Type", each not Date.IsInPreviousNDays([date], 3))

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one easy way to do this

 

1. Right click on your first query and choose Reference (so that you only load data once on refresh)

2. Click on the pull down on your Date column and choose Date Filters / In the Previous and choose 3 Days

 

You will get a step added that looks like this

=Table.SelectRows(#"Changed Type", each Date.IsInPreviousNDays([date], 3))

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks, @mahoneypat ,

 

That sounds like it's just going to give me the last 3 days, where I want everything but what happened in the last 3 days.

 

However, I think I've found an answer based on information I found here: - Convert DateTime into Date in Query Editor using M function 

 

#"Added Conditional Column" = Table.AddColumn(Source, "Custom", each if [Date] < DateTime.Date(Date.AddDays(Date.StartOfDay(DateTime.LocalNow()),-3)) then "Keep" else "Remove"),

This seems to give me what I want in a column, and then I can add a step to remove any row with "Remove" in that column.  Happy to look at alternatives though if you think your option can also work?

That would work too, or you could just add "not" to what I sent before

 

=Table.SelectRows(#"Changed Type", each not Date.IsInPreviousNDays([date], 3))

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks @mahoneypat 🙂

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.