cancel
Showing results for
Did you mean:
Highlighted
Regular Visitor

## 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
Highlighted
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
Highlighted
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.

Highlighted
Regular Visitor

## 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.

Highlighted
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.

Highlighted
Regular Visitor

## 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

#### August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

#### Super Users Coming in August

We are excited for the next Super User season.

#### Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

#### Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (6,886)