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 / Return Closest Value
Power Apps
Answered

Return Closest Value

(0) ShareShare
ReportReport
Posted on by 12

Hi all,

 

I have a SQL Table that has 2 columns, 'Lookup' and 'Result'.

The app requires 3 Inputs from the user and returns a decimal result.

 

I'm looking for way to search the SQL table and return the closest 'Result' where Value is <= the result of the calculation.

 

I have tried the Lookup formula:

LookUp(Ullage,Lookup<=Value(luCalc.Text),Result)

However this returns only the first value on the table.

 

I also thought about reducing the dataset and taking the last() value but I cant find a way to reduce it based on comparing numbers.

 

Can anyone offer any advice?

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @FosterM,

     

    Does the following code meet your requirements?

    Filter the Table and sort by descending order, then use First() to fetch the closest value to that number:

     

    //Only show the first (closest) record
    First(
     //Sort by closest value first
     Sort(
     //Fetch all rows that meet the requirement
     Filter(
     Ullage,
     Lookup <= Value(luCalc.Text)
     ),
     Result,
     Descending
     )
    )
    //You could write .Result after the last bracket to only fetch the Result column

     

    I based my code and column names on your example - adjust where necessary. (I don't know if the lookup <= Value() was meant to be Value <= Value())

     

    If this solves your question, would you be so kind as to accept it as a solution.

    Thanks!

  • FosterM Profile Picture
    12 on at

     

    Thank you @LaurensM,

     

    This worked perfectly as written. Interestingly I had to include the .Result - otherwise the filter() complained about expecting a text value. 

     

    You made the right assumption with the field name, thanks!

     

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 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard