Skip to main content
Community site session details

Community site session details

Session Id : iTcloh6wU97BhspE1eAp37
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

 

 

 

  • Verified answer
    timl Profile Picture
    35,242 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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete