Power Query text/date help!

matt3388

New Member
Joined
Sep 27, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

I've been trying to calculate a date from a week commencing date and day of the week (Mon, Tue, etc), but I'm struggling with Mon, Tue, being stored as text values.

I have the week commencing date which is stored as a date format in column one, titled "week commencing", and the day of the week (Mon, Tue etc) stored in text format in column two, titled "Day completed".

I'm looking to add a custom column which will give me the correct completion date for Tue, Wed, Thu etc, in the format of dd/mm/yyyy.

I want the week to run from Mon-Sun, so the date for Monday would match the week commencing date in column one.

Any help or ideas would be really appreciated, thank you.




I'm also using excel 365 on Windows 11
 

Attachments

  • Screenshot 2024-09-27 222516.png
    Screenshot 2024-09-27 222516.png
    11.7 KB · Views: 10

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
There are various ways this could be done. Maybe the most straight forward (in PQ) would be to load a new table of master data with the list of days and an integer.
Mon,0
Tue,1
Wed,2
Etc

Merge the original table with this new table and extract the integer column
Add a new custom column that adds the integer to the date
Make sure the original date column is date and not date/time, first
Custom column will need to be something like
[original date column name] + #duration([integer column name],0,0,0)
 
Upvote 0
Maybe something like this as an alternative? Just create a new blank query and paste the following code in the Advanced Editor dialog. Then you can adapt it to your own source.
I don't think you need the last step since you'll most likely need to format it in Excel, but here it is. ChangeType -> Using Local can be also used.
Power Query:
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s3PS0msVDAwUghOLShJzU1KLVIwMjAyUTAwsAIjJR2oGqVYnSGoPKQ0tXgwqQ9PTcmjo45YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Week commencing" = _t, #"Day completed" = _t]),
    ChangeTypes = Table.TransformColumnTypes(Source,{{"Week commencing", type datetime}, {"Day completed", type text}}),
    AddDayIndex = Table.AddColumn(ChangeTypes, "DayIndex", each List.PositionOf({"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"}, [Day completed])),
    ActualDayCompleted = Table.AddColumn(AddDayIndex, "Actual Day completed", each Date.AddDays([Week commencing], [DayIndex])),
    UnnecessaryFormatStep = Table.TransformColumns(ActualDayCompleted, {"Actual Day completed", each DateTime.ToText(_, [Format = "dd/MM/yyyy"])})
in
    UnnecessaryFormatStep

Week commencingDay completedDayIndexActual Day completed
2.09.2024 00:00Monday002.09.2024
2.09.2024 00:00Monday002.09.2024
2.09.2024 00:00Monday002.09.2024
2.09.2024 00:00Monday002.09.2024
2.09.2024 00:00Tuesday103.09.2024
2.09.2024 00:00Tuesday103.09.2024
2.09.2024 00:00Tuesday103.09.2024
2.09.2024 00:00Wednesday204.09.2024
2.09.2024 00:00Wednesday204.09.2024
2.09.2024 00:00Wednesday204.09.2024
 
Upvote 0

Forum statistics

Threads
1,223,101
Messages
6,170,116
Members
452,302
Latest member
TaMere

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