Power Query Question: Is it possible to create a conditional column referencing dates/date column

indrajeet_rajput

New Member
Joined
Sep 7, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
So would it be possible to create a conditional column in power query referencing a date column example order date
So, if order dates are from 12/2/2024 to 12/8/2024 it returns "Week 1" else if dates are from 12/9/2024 to 12/15/2024 it returns "Week 2" else if dates are from 12/16/2024 to 12/22/2024 it returns "Week 3" and so on...
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Choose a column, "order date". Select “Add a column”> “Date”> “Week of the month”.

Screenshot 2024-12-27 162259.png
 
Upvote 0
How about something like this:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    ChangedType = Table.TransformColumnTypes(Source,{{"order date", type date}}),
    AddSeedDate = Table.AddColumn(ChangedType, "seed date", each Date.FromText("01/12/2024"), Date.Type),
    AddWeekNo = Table.AddColumn(AddSeedDate, "WeekNo", each Number.RoundUp(Duration.Days([order date] - [seed date])/7)),
    RemoveSeedDate = Table.RemoveColumns(AddWeekNo,{"seed date"})
in
    RemoveSeedDate

1735311299444.png

1735311257344.png
 
Upvote 0

Forum statistics

Threads
1,225,357
Messages
6,184,479
Members
453,235
Latest member
dirtisbrown17

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