Jonathan
Jonathan

Reputation: 451

How to filter a table for distinct values Powerapps

I am new to Powerapps and I have noticed that the Distinct function returns a table of the distinct values(only returns the distinct column not the full row). Is there a way to filter a table so that it returns back a subset of the full table with distinct values in a specified column.

Upvotes: 0

Views: 10178

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87228

You can use the GroupBy function for this. Take a look at the documentation, or in the example below:

Assuming that cities is a table with the following values:

City Country Population
London UK 8615000
Berlin Germany 3562000
Madrid Spain 3165000
Rome Italy 2874000
Paris France 2273000
Hamburg Germany 1760000
Barcelona Spain 1602000
Munich Germany 1494000
Milan Italy 1344000

The expression GroupBy(cities, "Country", "Cities") will return a table with a column "Country", and a column called "Cities" whose value will be a table with all cities for that country.

You can then use functions such as AddColumns and Sum to aggregate the values of the inner table, like in the example below:

AddColumns(
    GroupBy(cities, "Country", "Cities"),
    "Sum of City Populations",
    Sum(Cities, Population))

In your tweets example, if you want to get one tweet from each day, you can have an expression like the one below:

AddColumns(
    GroupBy(Tweets, "crf1d_date_index", "Dates"),
    "SampleTweet",
    First(Dates))

Where it would have a new column with the first tweet from each date. Or if you want a single field from the group, you can have something like this:

AddColumns(
    GroupBy(Tweets, "crf1d_date_index", "Dates"),
    "FirstTweetTime",
    First(Dates).tweet_time)

Upvotes: 1

Related Questions