web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details
Power Apps - Building Power Apps
Answered

Need help calculating Median between 3 values into a label

Like (0) ShareShare
ReportReport
Posted on 10 Aug 2022 18:53:52 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

 

 

 

I have the same question (0)
  • Verified answer
    timl Profile Picture
    35,776 Super User 2025 Season 2 on 10 Aug 2022 at 20:10:42
    Re: Need help calculating Median between 3 values into a label

    @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

     

     

  • rubin_boer Profile Picture
    4,841 Super User 2024 Season 1 on 10 Aug 2022 at 19:56:16
    Re: Need help calculating Median between 3 values into a label

    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 885 Most Valuable Professional

#2
developerAJ Profile Picture

developerAJ 571

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 352 Super User 2025 Season 2

Last 30 days Overall leaderboard