cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JonRetro
Frequent Visitor

Need help calculating Median between 3 values into a label

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
timl
Super User
Super User

@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

 

 

View solution in original post

2 REPLIES 2
rubin_boer
Super User
Super User

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

hey there if you liked the post give it a thumbs up, and if it solved your question please accept it as a solution.
timl
Super User
Super User

@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

 

 

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (1,989)