# Duration.From

## What is Duration.From?

Duration.From is an M function that takes a decimal number as input and returns a duration value. The duration is expressed in days, hours, minutes, and seconds. The syntax of Duration.From is as follows:

Duration.From(number as any) as duration

``` Here, the argument "number" is the decimal number that you want to convert to a duration. How Does Duration.From Work? To understand how Duration.From works, let's take an example. Suppose you have a decimal number 1.5, which represents 1 day and 12 hours. When you pass this number to Duration.From, it will return a duration value of "1 day, 12 hours". Here is the M code for this: ```

Duration.From(1.5)

``` The output will be: ```

#duration(0, 36, 0, 0)

``` This output may seem a bit cryptic, but it can be easily decoded. The first argument of the #duration function is the number of days, the second argument is the number of hours, the third argument is the number of minutes, and the fourth argument is the number of seconds. So, the output "#duration(0, 36, 0, 0)" means "0 days, 36 hours, 0 minutes, and 0 seconds". How to Convert Duration to Other Units? Sometimes, you may want to convert a duration to other units, such as minutes, hours, or seconds. Luckily, M provides several functions that allow you to do this. Here are some examples: Duration.TotalSeconds Duration.TotalSeconds is an M function that returns the total number of seconds in a duration. Here is the syntax: ```

Duration.TotalSeconds(duration as duration) as number

``` Here, the argument "duration" is the duration that you want to convert to seconds. Here is an example: ```

Duration.TotalSeconds(Duration.From(1.5))

``` The output will be: ```

129600

``` This output means that the duration "1 day, 12 hours" contains 129600 seconds. Duration.TotalMinutes Duration.TotalMinutes is an M function that returns the total number of minutes in a duration. Here is the syntax: ```

Duration.TotalMinutes(duration as duration) as number

``` Here is an example: ```

Duration.TotalMinutes(Duration.From(1.5))

``` The output will be: ```

2160

``` This output means that the duration "1 day, 12 hours" contains 2160 minutes. Duration.TotalHours Duration.TotalHours is an M function that returns the total number of hours in a duration. Here is the syntax: ```

Duration.TotalHours(duration as duration) as number

``` Here is an example: ```

Duration.TotalHours(Duration.From(1.5))

``` The output will be: ```

36

``` This output means that the duration "1 day, 12 hours" contains 36 hours. Duration.From is a powerful M function that allows you to convert decimal numbers to durations in days, hours, minutes, and seconds. By using other M functions like Duration.TotalSeconds, Duration.TotalMinutes, and Duration.TotalHours, you can convert durations to other units as well. With this knowledge of the M code behind Duration.From, you can create custom functions and perform complex data transformations in Power Query. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,050.00 – £26,550.00 Select optionsContinue Loading Done Power Query and M Introduction £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Intermediate £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Advanced £395.00 – £9,750.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```