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
Based on your description, it seems like you are trying to create a custom function to convert time values expressed in seconds from midnight to a time format. However, the function you provided is incomplete and contains errors.
To fix the error you are encountering, you need to pass the table containing the column you want to convert as a parameter to the function. Here's an updated version of your function that should work:
(ColumnToConvert as any) => let Source = ColumnToConvert, Converted = Time.FromSeconds(Number.Mod(Source, 86400)) in Converted
This function takes a column as a parameter, converts the value in each row to a time format, and returns the converted column.
To apply this function to your table columns, you can use the "Add Custom Column" feature in Power Query. Select the column you want to convert, go to the "Add Column" tab, click on "Custom Column," and enter the formula above.
I hope this helps! Let me know if you have any further questions.