Custom columns in power query - Adding text to the weekofyear value

sadavies2906

New Member
Joined
Feb 5, 2011
Messages
45
I have created a custom column in a power query that returns the week number of a list of start dates using the following

=Date.WeekOfYear([Start Date])

Below is the output I get in the column header "WEEK", I want to get an output that looks like the column header "EXPECTED".

Not only do I need to add the text "Week" in front of the result but I also need the output to use the current day and work out if the start date is in the past with regards the week number and change those to the text "BACKLOG"

So if I opened the file today on the 20/02 which is week 8, all start dates prior to this week would return "BACKLOG", any start dates in this week would return "Week 8" and anything in the future would have its correct week number.

Hope I've explained this ok

Start DateWeekExpected
01-Apr14Week 14
02-Mar10Week 10
30-Jan5BACKLOG
23-Feb8Week 8
22-Feb8Week 8
17-Feb8Week 8
14-Feb7BACKLOG
20-Feb8Week 8
10-Jan2BACKLOG
15-Jan3BACKLOG
02-Feb5BACKLOG
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
M Code for your added column.
=if (Date.From (DateTimeZone.LocalNow()) < [Start Date]) then "Week " & Text.From(Date.WeekOfYear ([Start Date])) else "BACKLOG"
 
Upvote 0
I'd suggest this one
if Date.WeekOfYear([Start Date]) < Date.WeekOfYear(DateTime.LocalNow()) then "Backlog" else "Week "&Text.From(Date.WeekOfYear([Start Date]))
 
Last edited:
Upvote 0
actual date for this table is 21/02/2020
week: 8
Start DateWeek of YearCustom
01/04/202014Week 14
02/03/202010Week 10
30/01/20205Backlog
23/02/20208Week 8
22/02/20208Week 8
17/02/20208Week 8
14/02/20207Backlog
20/02/20208Week 8
10/01/20202Backlog
15/01/20203Backlog
02/02/20205Backlog
 
Upvote 0
Thanks both, works exactly as expected, however I forgot to say I will have dates from last year in the "start date" column so these need to flag as "BACKLOG".

Currently because I only asked about week number in initial question a 2019 week 49 is being returned as "Week 49" as its not less than "Week 8", is there a way to say any "Start Date" less than today is "BACKLOG" except for those in the current week?
 
Upvote 0
or try
if Date.WeekOfYear([Start Date]) < Date.WeekOfYear(DateTime.LocalNow()) or Date.Year([Start Date]) < Date.Year(DateTime.LocalNow()) then "Backlog" else "Week "&Text.From(Date.WeekOfYear([Start Date]))
 
Upvote 0
I have been trying to manipulate the code supplied by sandy666 as things have moved on since it was supplied.

if Date.WeekOfYear([Start Date]) < Date.WeekOfYear(DateTime.LocalNow()) or Date.Year([Start Date]) < Date.Year(DateTime.LocalNow()) then "Backlog" else "Week "&Text.From(Date.WeekOfYear([Start Date]))

I am now trying to get the following

Everything prior to and this week to return this weeks number and everything else to return its actual week number. Dates in 2021 can keep the system generated week number, dates in the past must be this weeks number

 
Upvote 0

Forum statistics

Threads
1,224,272
Messages
6,177,632
Members
452,786
Latest member
k3calloway

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top