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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to calculate Media...
Power Apps
Answered

How to calculate Median for a column in Gallery?

(0) ShareShare
ReportReport
Posted on by 133

Hi, 

I have a Gallery in which i'm applying these formulas and the output is correct:

 

Sum(Gallery8.AllItems,lbl_PriceUSD)

Average(Gallery8.AllItems,lbl_PriceUSD)

 

But when Median is applied, the formula is not recognized, the error is: Invocation of Unknown or unsupported function.

 

Median(Gallery8.AllItems,lbl_PriceUSD)

 

Could anyone give me some tip on how to solve it?

 

Thanks in advance.

 

image.png

Categories:
I have the same question (0)
  • Verified answer
    MF-12051538-0 Profile Picture
    406 on at

    Hi @acepeda ,

    There's a chance that a less complicated way exists -- but this is how I would solve this problem. Copy and paste the following code. I left notes in there that should hopefully make things a little easier to understand in there.

    Note that there are three places where I have "Price USD" in quotes that will need to be replaced with the name of the column in your table that is being referenced in the gallery label lbl_PriceUSD.

    Good luck.

    With(
    {rowcount: CountRows(Gallery8.AllItems)}, //define rowcount as the number of rows in Gallery8
    If(
    Mod(
    rowcount,
    2
    ) = 0, //does Gallery8 have even number of rows?
    Average( //if even # of rows, get average of two middle numbers
    Value(
    Last(
    FirstN(
    SortByColumns(
    Gallery8.AllItems,
    "Price USD", //this should be the name of the column in your table that is being referenced by lbl_PriceUSD
    Ascending
    ),
    rowcount / 2 //to get first middle number
    )
    ).lbl_PriceUSD.Text
    ),
    Value(
    Last(
    FirstN(
    SortByColumns(
    Gallery8.AllItems,
    "Price USD", //this should be the name of the column in your table that is being referenced by lbl_PriceUSD
    Ascending
    ),
    (rowcount / 2) + 1 //to get second middle number
    )
    ).lbl_PriceUSD.Text
    )
    ),
    Value( //if odd # of rows, get value of middle number
    Last(
    FirstN(
    SortByColumns(
    Gallery8.AllItems,
    "Price USD", //this should be the name of the column in your table that is being referenced by lbl_PriceUSD
    Ascending
    ),
    RoundUp(
    rowcount / 2, //to get middle number
    0
    )
    )
    ).lbl_PriceUSD.Text
    )
    )
    )


    If this solved your problem, please click Accept as solution.

  • acepeda Profile Picture
    133 on at

    Excellent... thanks so much!.   I really appreciate your help.

    I never thought the formula was so complex.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 335 Most Valuable Professional

#2
11manish Profile Picture

11manish 166

#3
sannavajjala87 Profile Picture

sannavajjala87 71 Super User 2026 Season 1

Last 30 days Overall leaderboard