Date Formula Support Needed

Bennets04

Board Regular
Joined
Jul 30, 2010
Messages
58
Good afternoon all,
I'm looking for some help with a BI Power Query formula (Trying to cut out lots of manual work) that will take a date from a column (So 10/07/2019) and return back whether that date was Last Week, Last Week -1, Last Week -2, etc up to Last Week -4 in a new column to the right of the date

Any help or support would be incredible

 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,744
what does that mean: Last Week -1? Last Week - one day? - one week?

anyway try:

Code:
[SIZE=1]= if Date.IsInPreviousNWeeks(Date.AddDays([Date],0),1) = true then 1 else if Date.IsInPreviousNWeeks(Date.AddDays([Date],7),1) = true then 2 else if Date.IsInPreviousNWeeks(Date.AddDays([Date],14),1) = true then 3 else if Date.IsInPreviousNWeeks(Date.AddDays([Date],21),1) = true then 4 else null[/SIZE]
it will give you a week number if date is in previous week (1), previous previous week (2), previous previous previous week (3) or previous previous previous previous week (4) else null :LOL:

DateDateNthWeek
10/07/2019​
10/07/2019​
1​
02/07/2019​
02/07/2019​
2​
25/06/2019​
25/06/2019​
3​
18/06/2019​
18/06/2019​
4​
10/06/2019​
10/06/2019​
18/07/2019​
18/07/2019​
03/07/2019​
03/07/2019​
2​
 

Bennets04

Board Regular
Joined
Jul 30, 2010
Messages
58
Hi mate,

This is brilliant thank you. All I meant was any dates from the previous week I want to be able to show LW, any dates from the week before that date would be LW-1 (Last week -1) and so on

I have loads of sales data by day but want to show some graphs to compare weekly data and in Excel i use LW, LW-1, LW-2, LW-3, LW-1 instead of lets say Week 36, Week 35, Week 34, Week 33, Week 32

Cheers
Steve
 

Bennets04

Board Regular
Joined
Jul 30, 2010
Messages
58
So managed to change the 'then 1' to 'then "LW" and it worked a treat!!

How would the same priniples work if i was just looking at weekend performance? How could i show if a date was lets say between Friday - Sunday lastweek then return a 1, Friday - Sunday the week before would be 2 etc etc?

Any thoughts?

Cheers
Steve
 

sandy666

Well-known Member
Joined
Oct 24, 2015
Messages
5,744
there are more function like:

  • Date.IsInPreviousDay
  • Date.IsInPreviousMonth
  • Date.IsInPreviousNDays
  • Date.IsInPreviousNMonths
  • Date.IsInPreviousNQuarters
  • Date.IsInPreviousNWeeks
  • Date.IsInPreviousNYears
  • Date.IsInPreviousQuarter
  • Date.IsInPreviousWeek
  • Date.IsInPreviousYear
etc...

see also: Power Query M Reference
 

Watch MrExcel Video

Forum statistics

Threads
1,102,021
Messages
5,484,236
Members
407,436
Latest member
smurfkings247

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top