web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Need help calculating ...
Power Apps
Unanswered

Need help calculating Median between 3 values into a label

(0) ShareShare
ReportReport
Posted on by 4

Right now I am working on a portal that returns median values for 3 numbers. I can only find Average, Sum, Max, and Min. The values are labeled "DataCardValue7" "DataCardValue18" and "DataCardValue1"

 

JonRetro_0-1660157530297.png

 

 

 

Categories:
I have the same question (0)
  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on at

    hi @JonRetro welcome to the community.

     

    you have some work to do to get to the median:

    Consider 3 labels txtM1, txtM2 and txtM3 with values 5, 3, 7

     

    The average and median will be the same

    rubin_boer_1-1660160959929.png

    Average, "Average: " & Average(txtM1.Text, txtM2.Text, txtM3.Text)

    The Median is as follows, "Median" " & 

    With(
     {
     _set: [txtM1.Text,txtM2.Text,txtM3.Text] //add the number to a table or collection
     },
     With(
     {
     _n: CountRows(_set), //get the number of elements, you can hardcode it to three if thats what you will use all the time
     _s: Sort(_set,Value(Value),Ascending) //sort the numbers in ascending order
     },
     If(
     Mod(_n,2) = 0, // choose the calculation based on teh number of elements, yours can be reduced to include Index(_s,(_n+1)/2).Value only as you have an uneven number 
     (Index(_s,(_n/2)).Value + Index(_s,((_n + 2) / 2)).Value) / 2 ,
     Index(_s,(_n+1)/2).Value
     )
     )
    )

     

    changing the values to show the effect

     

    Result

    rubin_boer_2-1660161363501.png

     

     

    Hope it helps,

    R

  • Verified answer
    timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    @JonRetro 

     

    The formula that @rubin_boer posted is great as it'll account for a dynamic number of input values.

    If you always have 3 inputs only, an alternative would be to sort the values and to retrieve item number 2, as that will return the medium.

     

    Index(
     Sort([
     Value(DataCardValue1.Text), 
     Value(DataCardValue18.Text), 
     Value(DataCardValue7.Text) 
     ]
     ,Value)
     , 2
    ).Value

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard