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 / Get the Max value with...
Power Apps
Answered

Get the Max value with filter or condition

(0) ShareShare
ReportReport
Posted on by 248

Hi there,

 

I'm trying to build a "serial numer", but need a conditional, until today I did it using "CountRows(Filter(", but I have the problem with non delegable formulas.

 

So I think maybe is possible do it with Max funtion, but I don't know how I can do it.

 

My alternative code that I'm trying is:

 

 

Max(Filter('[dbo].[tbPO]';IdProject = proyecto).Line)+1

 

 

If not possible, How I can do it to avoid the issues with non delegable functions?

 

Thank you.

 

 

 

Categories:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 Moderator on at

    @Manarjomar 
    MAX cannot be delegated: so just use a Sort function instead.  It does the same thing.

    Sort(Filter('[dbo].[tbPO]';IdProject = proyecto),Line, Descending).Line+1

     

    Note: I assume 'Line' is a number type.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • eka24 Profile Picture
    20,925 on at

    Try:

    Max('[dbo].[tbPO]';IdProject)+1

    Max(Datasource,Column)+1

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

     

     

  • Manarjomar Profile Picture
    248 on at

    Hi@mdevaney ,

     

    Yes, you are right, "Line" is a number, but the function doesn't work:

     

    Screenshot_1.pngScreenshot_2.png

     

    My last function was:

     

    Screenshot_3.png

     

    Regards.

  • Verified answer
    mdevaney Profile Picture
    29,991 Moderator on at

    @Manarjomar 

    I missed the FIRST function.  Include this:

     

    Sort(First(Filter('[dbo].[tbPO]';IdProject = proyecto),Line, Descending)).Line+1


    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • Verified answer
    Manarjomar Profile Picture
    248 on at

    Thank you @mdevaney your formula doen't work, but I understood your idea and I found that only was an order error. Finally works with this one:

     

    If(FormPO.Mode = FormMode.New ; First(Sort(Filter('[dbo].[tbPO]';IdProject = proyecto);Line; Descending)).Line+1;DataTablePO.Selected.Line)

     

    Thank you for your help.

     

    Regards.

     

     

  • HFG Profile Picture
    524 on at

    Hi @mdevaney , 

    Jumping on this post in case you can help. I have created an application for customer service tickets. For each ticket there is an increasing ID per store. The code below was working fine until I loaded the database with the tickets from an old system where there is no ID. For stores where there aren't many tickets the code still works. For the ones where there are lots of tickets it is creating all the IDs as 1. I suspect this is due to delegation issues and the last ticket it is getting is one of the ones with no ID. From what I see, Sort is delegable, but Last is not. Do you have any ideas how I could rework this code so it correctly gets the last highest ID ?

    HFG_0-1686562489486.png

    I think the code is quite self explanatory but just in case: I filter the list to get tickets for the selected store, sort it by ID ascending and then take the last and add 1. 
    Thanks

  • HFG Profile Picture
    524 on at

    I believe I have managed to fix this by using a collection. I first collect using Sort, Descending on the ID and then use the First(Collection).ID + 1. 

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 463

#2
WarrenBelz Profile Picture

WarrenBelz 364 Most Valuable Professional

#3
11manish Profile Picture

11manish 275

Last 30 days Overall leaderboard