0

I have a table in Power Query that has multiple date columns in a specific Julian Date format. I would like to change all of them at once into the classic date format by using this function:

Date.AddDays(#date(Number.RoundDown([Date1]/1000)+1900,1,1),Number.Mod([Date1],1000)-1)

For now I doing this steps for every column:

  1. Add custom column with the function above
  2. Delete old column
  3. Rename new column

Is there any way to do this more harmonized for all selected columns at once?

Example Data:

enter image description here

1 Answer 1

1

You could create a function in Power Query.

  1. New Source -> Blank Query

Than e.g. for testing you could use this example. Write in advanced editor in this new blank query:

let YourFormula = (input) =>
        input * 2
in YourFormula

Now it looks like:

enter image description here

In this field you can test your function.

After that you can go into your main table and add in the advanced editor at the end of code:

Transform = Table.TransformColumns(#"Removed Columns2", {{"PROJECTID", Query1}, {"ACCRUED", Query1}})
in
    Transform

This transforms the selected columns inplace. No need for adding a new one, deleting the old one and renaming.


Update according comments, now with your specific data.

Formula of the function:

let YourFormula = (input) =>
    Date.AddDays(#date(Number.RoundDown(input/1000)+1900,1,1),Number.Mod(input,1000)-1)
in
    YourFormula

Code in the main table:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNDAwVNIBMQxNjZRidaBiRjAxM4SYMUzMAiFmAhEzMjVQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date1 = _t, Date2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date1", Int64.Type}, {"Date2", Int64.Type}}),
    Transform = Table.TransformColumns(#"Changed Type", {{"Date1", Query1}, {"Date2", Query1}}),
    #"Changed Type1" = Table.TransformColumnTypes(Transform,{{"Date2", type date}, {"Date1", type date}})
in
    #"Changed Type1"

Table before and after:

strong text

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot. Is this really working with my function above? In the function is a variable/ placeholder for a column [Date1].
Could you provide me some test raw data, even its just a table here in SO.
Just provided some example data in the initial post
see update and let me know if it worked.

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.