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 / Find the maximum batch...
Power Apps
Unanswered

Find the maximum batch number in the database

(0) ShareShare
ReportReport
Posted on by 143

Hi All,

 

In my Sql db Title column group of attachments are stored as batch 1, batch 2 so on.. I want to check through PowerFx max no of batch number stored in database then increment it. if it is Null then It should be batch 1 if it is batch 1 then stored as batch 2 and so on.... below code

 

// initialize batch counter
ClearCollect(batchCount, {value: 1});

// find the maximum batch number in the database
ClearCollect(
maxBatch, LookUp(myimages, !IsBlank(Title))

);

// check if the maximum batch number exists and increment it
If(
CountRows(maxBatch) > 0,
Patch(
batchCount,
First(batchCount),
{value: Value(Right(First(maxBatch).Title, 1)) + 1}
),
// otherwise increment the batch counter
Patch(batchCount, First(batchCount), {value: First(batchCount).value + 1})
);

 

 

In code : // find the maximum batch number in the database
ClearCollect(
maxBatch, LookUp(myimages, !IsBlank(Title))------ I have troubled find the max batch number in db . Also lookup function might not work in large dataset..... can anyone help it




Thanks,

Chiranjit

Categories:
I have the same question (0)
  • rswain Profile Picture
    173 on at
    To find the maximum batch number in the database, you can use the Max function to get the maximum value of the Title column where the Title column contains the string "batch" and a number. Here's an example:
    
    ClearCollect(maxBatch, Filter(myimages, StartsWith(Title, "batch") && IsNumeric(Substitute(Right(Title, Len(Title)-5), ".", ""))));
    ClearCollect(maxBatchNumber, {value: If(CountRows(maxBatch) > 0, Max(Table(maxBatch, "value")), 0)});
    
    This will first filter the myimages table to only include rows where the Title column starts with the string "batch" and is followed by a number. Then, it will calculate the maximum value of the value column in the maxBatch collection. If there are no rows in the maxBatch collection, it will set the maximum batch number to 0.
    
    Note that this assumes that the batch number is always at the end of the Title column and is separated by a space from the preceding text. If this is not the case, you may need to modify the Substitute and Right functions to extract the correct batch number.
  • sahachiranjit32 Profile Picture
    143 on at

    There  is an issue with this line:

    && IsNumeric(Substitute(Right(Title, Len(Title)-5), ".", ""))) --- Delegation warning 

    ClearCollect(maxBatchNumber, {value: If(CountRows(maxBatch) > 0, Max(Table(maxBatch, "value")), 0)}); -- can't use non record value . 

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 396 Most Valuable Professional

#2
11manish Profile Picture

11manish 134 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 101 Super User 2026 Season 2

Last 30 days Overall leaderboard