Power Apps Set ThisItem Value [With Real Examples]

In this Power Apps Tutorial, We will learn how to set a ‘ThisItem‘ operator within the Power Apps. Also, We will discuss how to work with the ThisItem operator within the Power Apps gallery based on different scenarios.

Currently, We got a requirement from one of our clients while working with a certain canvas app. As per their requirement, they want to set a variable value using the ThisItem operator.

Also, Read: How to Select First Item in a Power Apps Gallery

What is Power Apps ThisItem?

In Power Apps, ThisItem is a formula that refers to the currently selected item in a gallery or form control. When a user interacts with a gallery or form control, Power Apps automatically sets the context of ‘ThisItem‘ to the item that was selected.

The Power Apps ThisItem refers to the properties of the currently selected item, such as its ID or name, in formulas and expressions throughout your app. That is, it represents the current data structure for each section of the record within the respective gallery.

Working with the Power Apps ThisItem

Here, we will see how to work with the Power Apps ThisItem operator within a gallery control. For this, the following steps are:

  • On the Power Apps screen, add a blank vertical gallery.
  • Add a text control to the Power Apps gallery. We can see as the gallery didn’t connect with any data source, it will display a sample text within the text control with the below expression.
Text = ThisItem.SampleText
Power Apps ThisItem
Power Apps ThisItem
  • Let’s add a button control to the gallery and create a global variable to store the SampleText of each section of the record.
  • For this, add a button control to the above Power Apps gallery and insert the below expression on the button’s OnSelect property.
OnSelect = Set(VarValue, ThisItem.SampleText)
Set ThisItem in Power Apps
Set ThisItem in Power Apps
  • Again, we will add a text input control on the outside of the Power Apps gallery. Insert the below expression on the Text property.
Text = VarValue

Where VarValue is the name of the global variable that we have created. Now, we can see when we click any button the respective item will be displayed on the text input control.

Power Apps set ThisItem value
Power Apps set ThisItem value

This is how to work with the ThisItem value in Power Apps.

See also  Power bi create a date table - Complete tutorial

Check out: How to get selected value from gallery in Power Apps?

Set ThisItem value in the Power Apps gallery

Here, we will see how to set a value using the ThisItem operator within a Power Apps gallery. For this, we have a SharePoint list based on ‘Content Scheduler’ having different types of columns such as single line of a text column, choice column, and date as shown below:

Power Apps set ThisItem value in a gallery
Power Apps set ThisItem value in a gallery

On the Power Apps screen, let’s add a blank vertical gallery and connect the gallery with the above SharePoint list.

How to set ThisItem value in Power Apps gallery
How to set ThisItem value in a Power Apps gallery
  • Add a text label control to the above Power Apps gallery and insert the below expression on the Text property to display the content’s title.
Text = ThisItem.Title

Once we insert the above formula it retrieves all the data from the title column of the specified SharePoint list.

PowerApps set ThisItem value in a gallery
PowerApps set ThisItem value in a gallery
  • Similarly, we can add another text label control to display the date column data. For that, the expression will be as below:
text = ThisItem.'Draft Date'
Set ThisItem in Power Apps gallery
Set ThisItem in Power Apps a gallery
  • In the case of the choice column, the expression will be a little different. For this, add a text label control to the Power Apps gallery and insert the below expression on the Text property to display the blog status value.
Text = ThisItem.'Blog Status'.Value
How to set ThisItem value in a Power Apps gallery
How to set ThisItem value in a Power Apps gallery

Similarly, we have added 2 more text label control to add publish date and blog type as shown below:

PowerApps set ThisItem value in gallery
PowerApps set ThisItem value in a gallery

This is how to set the ThisItem value in a Power Apps gallery.

Have a look: How to add text input to Power Apps collection?

Update ThisItem value in Power Apps gallery

In this section, we will discuss how to update a value in Power Apps gallery using the ThisItem property. That is, we will add an icon to the above Power Apps gallery. When the user clicks on that icon, the respective item’s ‘publish date’ will be updated to a specific date value.

See also  Power BI Measure Filter

To work with this scenario, the following steps are:

  • Add an icon (calendar or right) to the above Power Apps gallery.
  • Insert the below expression on the icon’s OnSelect property.
OnSelect = Patch(
    'Content Scheduler',
    ThisItem,
    ContentScheduler_Gallery.Selected,
    {'Publish Date': Today()}
)

Where

  • ContentScheduler_Gallery is the name of the above Power Apps vertical gallery.
  • ‘Publish Date’ is the name of the date column where the date value will be updated.
  • Today() reveals the current date.
Power Apps update ThisItem value in a gallery
Power Apps update ThisItem value in a gallery

Let’s publish and preview the app. We can see when we click on any icon the respective date value will be updated within the above gallery.

Update ThisItem value in Power Apps gallery
Update ThisItem value in Power Apps gallery

This is how to update a particular item’s value by using the ThisItem in a Power Apps gallery.

Furthermore, you may like some more Power Apps tutorials:

Conclusion

From this Power Apps Tutorial, we learned all about Power Apps ThisItem property based on different scenarios. Such as:

  • What is Power Apps ThisItem?
  • How to work with the Power Apps ThisItem?
  • Set ThisItem value in the Power Apps gallery.
  • How to update the ThisItem value in a Power Apps gallery?
>