Forum Discussion

leebaldwin's avatar
leebaldwin
Helper I
3 years ago
Solved

Pulling Data for A Week

Good afternoon: I have the following sql statement that I have written and it is pulling in data with no issue. My problem is that we want to have a full weeks of data. So, for this week (02/06 - 02...
  • lbendlin's avatar
    lbendlin
    3 years ago

    what should happen when you run this on a sunday?  Still the same rule ( ie take the previous sunday) ?

     

    let
        Source = List.Dates(#date(2023,1,1),60,#duration(1,0,0,0)),
        #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
        #"Added Custom" = Table.AddColumn(#"Converted to Table", "Previous Sunday", each let d=Date.DayOfWeek([Column1]), p=if d=0 then 7 else d, r=[Column1]-#duration(p,0,0,0) in r)
    in
        #"Added Custom"

    How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".