Forum Discussion
imranamikhan
4 years agoHelper V
Power Query Last 7 Days From Max Date Column
Hi everyone, I want to use Power Query to add a custom column which identifies whether a date value from a date column is "within" or "outside" the last 7 days from the maximum date in the date ...
- 4 years ago
Sorry. Forgot that part. Here you go.
let maxdate = List.Max(#"Previous Step"[Date]) in if [Date] >= Date.AddDays(maxdate, -7) then "Y" else "N"
Pat
smpa01
4 years agoCommunity Champion
imranamikhan if you intend to bring only last 7 days of data from the SQL server, it will be lot easier and performant to do on the server-side
/*TSQL Query to get only data from last 7 days*/
select *
/*, CASE WHEN gl_date>=DATEADD(DAY,-7,GETDATE()) then 'within last 7days' else 'outside of last 7days' end as filter*/
from
[dbo].[Actuals]
where gl_date>=DATEADD(DAY,-7,GETDATE())
/*TSQL Query to identify if the data is from last 7 days*/
select *
, CASE WHEN gl_date>=DATEADD(DAY,-7,GETDATE()) then 'within last 7days' else 'outside of last 7days' end as filter
from
[dbo].[Actuals]
/*where gl_date>=DATEADD(DAY,-7,GETDATE())*/
imranamikhan
4 years agoHelper V
Thanks for the suggestion smpa01 but there is a specific reason I want to use Power Query as opposed to delegating back to SQL server.
- smpa014 years agoCommunity Champion
imranamikhan sure no worries