Second

How to Use the Power Fx SecondĀ  Function in Power Apps

What is the Power Fx Second Function?

The Power Fx Second function is a powerful tool in Power Apps that allows you to extract the second value from a specified date/time value. This function is particularly useful when you need to perform calculations or comparisons based on the second value of a date/time value.

Syntax

The syntax for the Power Fx Second function is as follows:


Second( DateValue )


Where `DateValue` is the date/time value from which you want to extract the second value.

Examples

Let's take a look at some examples of how to use the Power Fx Second function in Power Apps.

Example 1: Displaying the Second Value of a Date/Time Value

Suppose you have a date/time value stored in a variable called `MyDateTime` and you want to display the second value of this value in a label control. Here's how you can do it:

1. Insert a label control onto your screen.

2. Set the Text property of the label control to the following formula:


“Second Value: ” & Second( MyDateTime )


This formula concatenates the string "Second Value: " with the result of the Second function applied to the `MyDateTime` variable.

3. Run your app and observe the label control. You should see the second value of the `MyDateTime` variable displayed next to the string "Second Value: ".

Example 2: Highlighting Rows Based on Second Value

Suppose you have a gallery control that displays a list of items, and each item has a date/time value associated with it. You want to highlight the rows in the gallery where the second value of the date/time value is even. Here's how you can do it:

1. Add a rectangle control to your gallery template.

2. Set the Fill property of the rectangle control to the following formula:


If( Mod( Second( ThisItem.DateValue ), 2 ) = 0, Color.Red, Color.Transparent )


This formula uses the Second function to extract the second value from the `DateValue` property of the current item in the gallery (`ThisItem`). It then uses the Mod function to determine if the second value is even. If it is, the Fill property is set to red; otherwise, it's set to transparent.

3. Run your app and observe the gallery. You should see the rows with even second values highlighted in red.

In this article, we've explored the Power Fx Second function and demonstrated how it can be used in Power Apps. By using this function, you can extract the second value from a date/time value and perform a variety of calculations and comparisons based on that value. So why not give it a try and see how it can enhance your Power Apps experience?

Power Apps Training Courses by G Com Solutions (0800 998 9248)