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 / When adding new row to...
Power Apps
Unanswered

When adding new row to gallery, automatically fill period with next from list

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I have a gallery that's getting data from a SQL data source.  
In my gallery there are three columns, Project, Period and value.

I have a button that adds a new row to my table based on what project is selected in another gallery. 
I would like to also add period automatically so that the user does not have to fill this in. What I would like is whatever period is the greatest, then when onselect button, it adds the next row with the next period.

 

My code is the following.

 

Gallery:

Sort(Filter('[dbo].[Table]',
ProjectID = SelProj,),
Period,
Descending)

Button to add new row:
Patch(
'[dbo].[Table]',
Defaults('[dbo].[Table]'),
{
ProjectID:SelProj,
}
)

I'm guessing something should be added to the last code snippet, but not sure how.

 

My period column is in text format "YYYYMM", but I have created a datacolumn as well, in case that is needed.

 

Really appreciate any help!

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 
    It's hard to be dead on with this suggestion as there as some factors not revealed in your post that would be helpful, but taking a first cut at it, consider the following for your formula:

    Patch('[dbo].[Table]',
     Defaults('[dbo].[Table]'),
     {
     ProjectID:SelProj,
     Period: Text(Max(AddColumns(yourGallery.AllItems, "_pd", Value(Period)), _pd) + 1)
     }
    )

    This is based on the assumption that your Period column is text and that, as you mention, it is in the YYYYMM format.

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Thanks @RandyHayes , This works well inside a year. Wonder if it might be better to use my date column to handle this problem. Potentially to some similar logic? Any idea how. I would like it to always be the first in the following month. Any suggestions on 'how to solve that?

     

    Thanks!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Yes, I was suspecting there was some other logic that really needed to play into this as the turn of a year could be a factor.

    The first of the following month can easily be determined though.

    As an example: 

       DateAdd(Date(Year(Today()), Month(Today()), 1), 1, Months)  

    will give you the first day of next month.

     

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard