DEV Community

Cover image for Calculate Frequency and Mode of a Value in a Collection in Power Apps
Mark Nanneman
Mark Nanneman

Posted on

1 1 1

Calculate Frequency and Mode of a Value in a Collection in Power Apps

The mode of a number or data set can be a useful statistic. There are some situations when the mean or average isn’t as helpful as the mode. The mode can give you the idea of a trend or most popular choice. Another example I’ve encountered is needing to identify the typical price of a good or service from large data sets in which there might be some variance due to discounts or human error.

Getting statistics like Mode and Standard Deviation are easy enough in Power BI or Excel. In Power FX there is a Standard Deviation function, StdP().

There’s no built in way to calculate the Mode in Power Automate or Power Apps, but here’s how you can do it.

Step One – Calculate Frequency of Distinct Items in Collection

In this example I’m using a collection called “gbl_col_prices” with two columns, price and title.

Image description

To get a distinct collection of the titles in the collection, I use Distinct()

Image description

Step Two – Add a Frequency Count Column

Use the AddColumns() function. The new column is called freq. The value for the new column is calculated by CountRows() on a filter of the original collection filtered by title = Value.

Value represents the Distinct Title from the previous step in the expression.

Image description

Then add a Sort() to sort by the new freq column in descending order.

Image description

Displayed in a gallery, the new collection of distinct titles with frequency counts now looks like this:

Image description

Step Three – Calculate Max Frequency

Use a Max() function on the distinct collection with added frequency count column we created in the steps above.

Max(<your_distinct_frequency_collection>,freq)
In my example, I display this in a text control like this:

Image description

Step Four – Find Modes

For most purposes, you can just filter your frequency collection for all items that match the max frequency, and take the first item to get your mode.

Technically, a set can have multiple modes, and you might want to display these, or take the middle mode.

In this example, I have a further break down where I check for frequencies of distinct prices for a select product, and display all the modes found in a gallery.

Image description

Expression for displaying all modes found in a gallery:

Image description

Expression for displaying first, middle and last mode found in a text control:

Image description

Image description

Thanks for reading!

If you found this post helpful please give it a like. Power Platform Developer | [LinkedIn | Wordpress | YouTube: Mark’s Power Stuff | Buy me a coffee

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed: Zero in on just the tests that failed in your previous run
  • 2:34 --only-changed: Test only the spec files you've modified in git
  • 4:27 --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • 5:15 --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • 5:51 --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

Watch Full Video 📹️

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay