0

I have a column in power query called "Delivery Date", type date.

I want to convert the date to serial number (the same as in excel when you change type date to "general" format. My date is "yyyy-mm-dd"

example:

"2023-02-01" formatted as "44958"

"2023-01-31" formatted as "44957"

This is the output I would like:

Delivery Date DateCode
2023-02-01 44958
2023-01-31 44957

I've tried this code:

= Table.TransformColumnTypes(Source,{{"Delivery Date", Number.From}})

as well as duplicating my "Delivery Date" column and changing Type to "Int64"

in both cases my output is 6.38108E+17 for Feb 1st date, and 6.38107E+17 for Jan 31st date.

I have not been able to find a solution anywhere online thus far and have been formatting it once it's loaded into excel (which is an unnecessary step).

Thanks!

2
  • There is something else going on. Either of your methods will convert a "real date" to the correct serial number. Try setting up a table with ONLY those two dates, and try your method again. Commented Feb 2, 2023 at 22:08
  • Ok, all those methods worked when I created my own simple excel table and loaded into Power Query. It must be the query I'm using that's pulling from Azure Data Explorer. Thanks for the answers and tips. Commented Feb 2, 2023 at 23:38

1 Answer 1

1

How about

let  Source = #table({"Delivery Date"},{{"2023-02-01 5:00:00 AM +00:00"}}),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Delivery Date", type datetime}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Changed Type",{{"Delivery Date", type number}})
in  #"Changed Type1"
  • Transform to date/time
  • Transform again to number, without replacing original transformation
  • Sign up to request clarification or add additional context in comments.

    2 Comments

    I've tried changing to decimal number, and whole number, but get the same result. n both cases my output is 6.38108E+17 for Feb 1st date, and 6.38107E+17 for Jan 31st date.
    In its original source, it comes in as "2023-02-01 5:00:00 AM +00:00", which I then change to Date type, giving me "2023-02-01"

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.