Power Query

linkn00

New Member
Joined
Aug 15, 2019
Messages
44
Office Version
  1. 365
Platform
  1. Windows
I am encountering a situation where the date is both text and number. the date is format as dd/MM/yyyy.
the other date is format as MM/dd/yyyy.
We can see it in excel but power query just shows everything as a date or error. I want to have it convert everything to month/date/year.Please help. thank you
View attachment 112141
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If they are both number dates in Excel and not text, then reformat them in Excel to Numbers. True Dates are numbers, 1 up from 1/1/1900. Then import them into PQ.
 
Upvote 0
If they are both number dates in Excel and not text, then reformat them in Excel to Numbers. True Dates are numbers, 1 up from 1/1/1900. Then import them into PQ.
they are numbers and text. i don't want to do this in Excel because this is not a one-time thing. I will get a new CSV file every day. this is the reason why i choose power query
 
Upvote 0
Suggest you offer up some sample data using XL2BB so that we can run some Mcode on some data that reflect some actual data. Your attachment is not visible to us.
 
Upvote 0
There may be an easier means but this will work

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Added Custom" = Table.AddColumn(Source, "Is Date", each try Value.Is(Number.From ([Date]), type number) otherwise false),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", each if [Is Date] = false then [Date] else null),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Custom.1", "Custom.2", "Custom.3"}),
    #"Merged Columns" = Table.CombineColumns(#"Split Column by Delimiter",{"Custom.2", "Custom.1", "Custom.3"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged"),
    #"Added Custom2" = Table.AddColumn(#"Merged Columns", "New Date", each if[Merged]="//"then [Date] else [Merged]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom2",{{"New Date", type date}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"New Date"})
in
    #"Removed Other Columns"

Book3
ABC
1DateNew Date
21/3/20241/3/2024
36/5/20246/5/2024
425/12/202412/25/2024
516/10/202410/16/2024
66/4/20246/4/2024
Sheet1
 
Upvote 1
Solution
Suggest you offer up some sample data using XL2BB so that we can run some Mcode on some data that reflect some actual data. Your attachment is not visible to us.
sorry didn't know you could not see the picture. this is what the data looks like. i dont have the actual data with me but this is what it looks like
from a quick look at it, it looks like this
when setting the column to number it looks like this
23/01/2024
23/01/2024
1/23/2024​
45314​
 
Upvote 0
See my post nr 5. I am in the US, so my default is mm/dd/yyyy You can modify my code to reverse it for your default if necessary.
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,153
Members
452,615
Latest member
bogeys2birdies

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