cancel
Showing results for
Did you mean:
Highlighted
Level: Powered On

## How to find row number of currently selected item?

Hi,

I'm trying to wrap my head around how I can find the sum of specific rows from a Selected Gallery Item, as I want to create a report screen that shows the total costs of products that a business has.

Below is the table I'm using.

I want to find the sum of Cost1, Cost2 and Cost3 from a selected gallery, in this case Business 1, and output that number into a label.

I've gotten basic output data with Sum(Business, Cost1+ Cost2) and it shows the total cost of the column, but would like just the specific row.

I'm sure this is easy, but I'm new to powerapps and struggling to figure this out.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft

## Re: How to find row number of currently selected item?

Here is how to run the test from my previous message:

1. Create a blank app

2. Add a Blacnk vertical Gallery control and a Label control to the screen.

3. Select the Gallery control and paste the following into gallerie's "Items" property:

`[{a:1, b:10},{a:2, b:20},{a:3, b:30},{a:4, b:40}]`

This basically assigns a "table" with 4 rows and 2 columns to your gallery.

4. Select the Label control and paste the following into the "Text" property:

`Last(FirstN(Gallery1.AllItems, 2)).Value.a + Last(FirstN(Gallery1.AllItems, 2)).Value.b`

This formula basically says: From all the galleries items (Gallery.AllItems), get the "a" and "b" values from the second row (Last(FirstN(... , 2)) and add them together.

4 REPLIES 4
Microsoft

## Re: How to find row number of currently selected item?

The following test should help you calculate the sum values from 2 columns from the second row:

Gallery1.Items = [{a:1, b:10},{a:2, b:20},{a:3, b:30},{a:4, b:40}]

Label1.Text = Last(FirstN(Gallery1.AllItems, 2)).Value.a + Last(FirstN(Gallery1.AllItems, 2)).Value.b

The Label control should display "22" which is the sum of "a" and "b" column values from the second row.

Hope this helps.

Level: Powered On

## Re: How to find row number of currently selected item?

Thanks for the reply, but dont really understand too much of the code written. Where do I insert the Gallery1.Items part? Is that for the 'Items' value for my gallery, as I have tried that and it wouldn't allow it.

Is there any documentation on this topic that you can point me too?

Thanks.

Microsoft

## Re: How to find row number of currently selected item?

Here is how to run the test from my previous message:

1. Create a blank app

2. Add a Blacnk vertical Gallery control and a Label control to the screen.

3. Select the Gallery control and paste the following into gallerie's "Items" property:

`[{a:1, b:10},{a:2, b:20},{a:3, b:30},{a:4, b:40}]`

This basically assigns a "table" with 4 rows and 2 columns to your gallery.

4. Select the Label control and paste the following into the "Text" property:

`Last(FirstN(Gallery1.AllItems, 2)).Value.a + Last(FirstN(Gallery1.AllItems, 2)).Value.b`

This formula basically says: From all the galleries items (Gallery.AllItems), get the "a" and "b" values from the second row (Last(FirstN(... , 2)) and add them together.

Level: Powered On

## Re: How to find row number of currently selected item?

Fantastic!

Thanks for the help, it definitely clarifys things as I was wondering what the array was and how it should be put into powerapps.

Thanks dinusc!

Announcements

#### Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

#### Power Platform World Tour

Find out where you can attend!

#### Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

#### Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (4,531)