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)
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)})
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
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.
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.
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)})
I learn about concurrent() function and used it on the butoon concurrent call.
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.