Hi, need some help with Power Query. I connect PowerBI to Adobe and need to pull data from previous week only. Currently I use the following way to pull data for past 7 days.
Give this a go.
It assumes your week starts on a Monday. Don’t know if there are more places in your query where you call DateTime.FixedLocalNow() but you can store that in a a TodaysDate variable for example and call that instead.
If I publish my Dashboard and set up the scheduled refresh at the weekly basis, will the codes give me the data from the previous week every time? For example, if it is run today, it will give me the week of last week. If the dashboard refreshed in April 15th, it will give the previous week data based on April 15th?
Paste this code into a new blank query. It creates a list of dates for the previous week based on the TodaysDate variable. When you schedule a refresh and the M code get’s evaluated make sure you use the Date.From( DateTime.FixedLocalNow()) instead. The hard coded date below is only to demonstrate the expeced outcome for any given date, as you can see I’ve now passed April 15th.
let
TodaysDate = #date(2021, 4, 15), //Date.From( DateTime.FixedLocalNow()),
LastWeek = List.Transform({ Number.From(Date.AddWeeks( Date.StartOfWeek( TodaysDate,Day.Monday),-1))..Number.From(Date.StartOfWeek(TodaysDate,Day.Sunday))}, Date.From )
in
LastWeek
Hi @Mike, did the response provided by @Melissa help you solve your query? If not, how far did you get and what kind of help you need further? If yes, kindly mark as solution the answer that solved your query.
We’ve recently launched the Enterprise DNA Forum User Experience Survey, please feel free to answer it and give your insights on how we can further improve the Support forum. Thanks!