Forum Discussion
write a custom function to transform a column
- Anonymous3 years ago
Is there a Time.FromSeconds function in M? Why not just go
Table.AddColumn(ColumnToConvert, "Time", each Time.From(Value.Divide([ColumnToConvert], 86400)), type time)
No need for the Mod either.--Nate
Is there a Time.FromSeconds function in M? Why not just go
Table.AddColumn(ColumnToConvert, "Time", each Time.From(Value.Divide([ColumnToConvert], 86400)), type time)
No need for the Mod either.
--Nate
- ValeriaBreve3 years ago
Post Partisan
Anonymous , Adamboer
Thank you so much!!!!
So now I see where I was going wrong with my custom function - I had only seen examples of tables as inputs, so I was not sure where to start from. I could not find indeed the fucntion Time.FromSeconds so I ended up with the following as per Anonymous reply:
my function:
(ColumnToConvert as any) => let Source = ColumnToConvert, Converted = Time.From(Value.Divide(ColumnToConvert, 86400)) in Converted
used in my query:
= Table.TransformColumnTypes(Table.TransformColumns( PreviousStep,{"Confirmed Start Time", each fxConvertToTime(_)}),{"Confirmed Start Time",type time})
So I don't even have to add an extra column to delete it afterwards - much cleaner.
I also did not know that Time.From() could just work so simply on the division without the need for the rest...
Thank you both so much!
Kind regards
Valeria