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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
sbolton1855
Frequent Visitor

Get data for the last X days including today

I am trying to get data for the past 7 days including today I have tried in the previous 7 days and selecting 'today' (see img) but the next day it does not dynamically change.  The reason I am using >= is because if I only use = it only brings back 'today' at that date but 12am.

also if I select past 7 days it does not include today....

 

Today the query is 

= Table.SelectRows(Source, each Date.IsInPreviousNDays([datetime], 7) or [datetime] >= #datetime(2022, 8, 29, 0, 0, 0))

 

sbolton1855_0-1661958198574.png

 

I have tried to use: 

= Table.SelectRows(Source, each Date.IsInPreviousNDays([datetime], 7) or [datetime] >= #datetime(DateTime.LocalNow()))

but that didnt work.  How can I dynammically change the date to be today and the previous 7 days.

 

3 REPLIES 3
Lee-Parkland
New Member

try DateIsInPreviousDay + in previous (number of days you want to go back) days

OR

DateIsInPreviousDay + in next 24 + Hours

Rickmaurinus
Helper V
Helper V

Unfortunately Date.IsInPreviousNDays does not include the date of today. The image on this page illustrates this: https://powerquery.how/date-isinpreviousndays/

 

You could use: 

Table.SelectRows(
  Source, 
  each [datetime] >= Date.AddDays( DateTime.LocalNow(), -7 ) 
    and [datetime] <= DateTime.LocalNow() 
)

Notice that even if you subtract days from a datetime value, the output is still a datetime value (https://powerquery.how/date-adddays/). 

 

--------------------------------------------------

@ me in replies or I'll lose your thread

 

Master Power Query M? -> https://powerquery.how

Read in-depth articles? -> BI Gorilla

Youtube Channel: BI Gorilla

 

If this post helps, then please consider accepting it as the solution to help other members find it more quickly.

Vijay_A_Verma
Super User
Super User

Use

Date.IsInCurrentDay(Date.From([datetime]))

Hence use this

= Table.SelectRows(Source, each Date.IsInPreviousNDays([datetime], 7) or Date.IsInCurrentDay(Date.From([datetime])))

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

Check out the May 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors