cancel
Showing results for
Did you mean:
Regular Visitor

## Count items in multiple columns

I'm building an app for keeping track of upkeep.

There will be 8 columns that can have the value of 1, 2, 3, or 4.

I'd like to filter, sort and count the number of a certain value in all 8 columns.

For example:

there may be 4 rows who all have 1 adress linking them lets call it "adress x" .

They are then grouped by the adress linking them. Then I'd like to find all rows that have one or multiple "4"s in the 8 columns. Next I'd like to count the number of "4"s in the group "adress x". Finally I want to sort a list of multiple adress-groups by how many "4"s were found at that adress.

Is it possible? I haven't found what function to even start finding value x in multiple columns and rows.

8 REPLIES 8
Super User

If you're always looking for 4s, the simplest thing to do would be to add a calculated column to your data source that counts the number of fours on the row. If you had that, you could simply filter your gallery in power apps for rows where that value was > 0.

If that's not possible, you could filter the gallery for rows that had a four in any position, something like:

Filter(NumberList, Num1=4 || Num2=4 || Num3 = 4)

If you needed to know how many columns had a 4, you could add a calculated column to the table:

Or, use a variable so that you can look for other numbers besides four, and combine the two into one expression to use for the gallery:

``````AddColumns(
Filter(
NumberList,
Num1 = varNum || Num2 = varNum || Num3 = varNum
),
"NumberCount",
If(
Num1 = varNum,
1,
0
) + If(
Num2 = varNum,
1,
0
) + If(
Num3 = varNum,
1,
0
)
)``````

Regular Visitor

Thank you for your response Mike2500.

In your second paragraf, I'm guessing that "NumberList" is my own table, correct?

It seems like I would have access to inputting a formula column into my datasource. The interface is unguided however and I am unfamiliar with PowerFX. Would you know how the code would look to calculate all "x" in column "a", "b", "c"... etc.?

Super User

Yes, NumberList is the underlying table or sharepoint list.

What is your data source?  Are you using SharePoint, DataVerse, other?

Regular Visitor

I'm using Dataverse within the PowerApps for Teams enviroment

Super User

Ok, so the formula column you can add uses PowerFX, which is really the language used by power apps. So if your table has fields like num1, num2, etc., you can add the following as a formula:

If(num1=4,1,0+ If(num2=4,1,0) ...
Regular Visitor

Trying it, but keep getting an error that it was not possible to create or update the column. Might be a limitation or I'm doing something wrong...

Regular Visitor

Yep,

It's a limitation on dataverse for teams, cant use the function column.

I'll give the other method a go.

Thank you for your help and patience.

Regular Visitor

I did the in App version, but I'm having some trouble getting in the "groupby" function.

I've attached photos. The output is one line per "space" seen by the numbered bold labels. (eg. 101, 3 etc). I want to group them by the adress (eg. Repslag..., Evagat...). But when I try to nest the groupby function I can't seen to find where to put it.

Announcements