Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

AlmasMahfooz/finding-the-number-challenge

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

finding-the-number-challenge

Finding the number that appears the most in the given list of Random Numbers in Canvas App

[Code Challenge #6: Integer Counting] (https://stackoverflow.com/beta/challenges/79766578/code-challenge-6-integer-counting)

# CODE

UpdateContext({cvTimerStart: Now()});

ClearCollect(
    RandomNoCounts,
    Sort(
        ForAll(
            GroupBy(Table1, RandomNo, GroupedItems),
            {
                Item: RandomNo,
                Count: CountRows(GroupedItems)
            }
              ) 
         
    ,Count,SortOrder.Descending)
   
);
UpdateContext({cvTimerEnd: DateDiff(cvTimerStart, Now(), TimeUnit.Milliseconds)})

# RESULT

The Top value from descending order will gives the number that appears the most. In this case result is 284, 284 appears 23 times.

First(Sort(RandomNoCounts,Count,SortOrder.Descending)).Item

Uploading image.png…

Approach explanation

I used Microsoft Power Platform (Low Code/ No Code) Canvas app to solve this challenge. Import all 3 csv files provided for testing in Excel table format and used them with Data Table control.

Uploading image.png…

There are 3 buttons 100 Random Number,10000 Random Numbers and 1M Random Numbers, Each button have the same code as the one shared above. Data Tables show the number with number of times they appear.

Code Execution runtime.


To find out how long these fx code takes to generate random number and then group them according to their frequency and fills the data table, I used Date difference field to calculate time in millisecond, below lines from the above code do the calculations and on Label items property shows the time.

UpdateContext({cvTimerStart: Now()});
UpdateContext({cvTimerEnd: DateDiff(cvTimerStart, Now(), TimeUnit.Milliseconds)})

Anything you learned


I learn about concurrent() function and used it on the butoon concurrent call.

Uploading image.png…

The Concurrent() function in Power Fx for Power Apps allows multiple Power Fx functions or formulas to execute simultaneously, rather than sequentially, to improve application performance, especially for tasks like loading data or configuration details.

#What it does

1.Parallel Execution: Instead of running one formula after another, Concurrent() runs them at the same time, potentially reducing the total processing time. 2.Performance Improvement: This is especially beneficial for scenarios where the app needs to load multiple independent data sources or configuration settings when it starts up.

About

finding the number that appears the most in the given list of Random Numbers in Canvas App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.