cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Selecting the TOP1 record from lookup

I have this lookup: LookUp('[dbo].[T01]';MiningType=DataCardValue20.Selected.Value && MineID=DataCardValue15.Text;ID)

What to add to get the top value, or last record from this lookup? 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Anonymous 

LookUp ONLY returns one record.  There is nothing to get the top one as there is only one.

So, if you are referring to something like getting the most recent, then you need to sort the list in a reverse chronological order.

Since you are using a SQL table, do you have any field in it that distinguishes the date it was created or some sequential number field...like perhaps the ID field you reference in your formula?

For example, If ID is a sequential field then the following would give you the most recent:

LookUp(
    SortByColumns('[dbo].[T01]';
        ID; Descending
    );
    MiningType=DataCardValue20.Selected.Value && MineID=DataCardValue15.Text;
    ID
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
RandyHayes
Super User
Super User

@Anonymous 

LookUp ONLY returns one record.  There is nothing to get the top one as there is only one.

So, if you are referring to something like getting the most recent, then you need to sort the list in a reverse chronological order.

Since you are using a SQL table, do you have any field in it that distinguishes the date it was created or some sequential number field...like perhaps the ID field you reference in your formula?

For example, If ID is a sequential field then the following would give you the most recent:

LookUp(
    SortByColumns('[dbo].[T01]';
        ID; Descending
    );
    MiningType=DataCardValue20.Selected.Value && MineID=DataCardValue15.Text;
    ID
)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Anonymous
Not applicable

This is what I was looking for thanks. And yes the ID column can be sorted.

Anonymous
Not applicable

@RandyHayes how would I then add a +1 to this number I got from lookup? Keep in mind that the returned value is not all intiger, it looks like this: R001-2000001. So the number I would like to get in this example is R001-2000002.

 

RandyHayes
Super User
Super User

@Anonymous 

Well...since it is not a numeric value you are getting, you need to convert it to such.  I assume you are stating the ID is in that format.

I don't know if that pattern is the pattern it will always have.  If so, then the following will give you the next number:

With({_lookupValue: LookUp(SortByColumns('[dbo].[T01]';
                                            ID; Descending);
                           MiningType=DataCardValue20.Selected.Value && 
                           MineID=DataCardValue15.Text;
                           ID)},
    With({_prefix:Left(_lookupValue;5);
          _numVal: Value(Right(yourReturnedValue; 7))};

        _prefix & Text(_numVal + 1)

    )
)

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,590)