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 / Add next month to new ...
Power Apps
Answered

Add next month to new row in gallery

(0) ShareShare
ReportReport
Posted on by

Hi,

I have a gallery where the user currently is inserting new rows, where project comes automatically and then the user will have to fill out value and period (date format as a datepicker input).
I would like this datepicker to be automatically filled out with the first in the next month after the previous max row date. 

Any suggestions in how to solve this? I have tried with dateAdd and similiar things but can't seem to get it to work.

The button I have for new row has the following code:

 

Patch(
'[dbo].[Table]',
Defaults('[dbo].[Table]'),
{
Project: SelProj,
Client: Gallery_overview.Selected.dropclient.Selected.client,
}
)

 

Example of a row looks like this:

ProjectValueDate
99993428/1/2021

 

Then I would like the next row to become like this after hitting the "add new row" button:

ProjectValueDate
9999null9/1/2021

 

 

Any help solving this would be really appreciated!

 

Thanks!

Categories:
I have the same question (0)
  • timl Profile Picture
    36,393 Super User 2025 Season 2 on at

    Hi @Anonymous 

    Something like this should hopefully work:

    With(
     {lastRecord:
     First(FirstN(SortByColumns('[dbo].[Table]',"Date"), 1))
     },
     Patch(
     '[dbo].[Table]',
     Defaults('[dbo].[Table]'),
     {
     Project: Gallery_overview.Selected.txtProjname.Text,
     Date:lastRecord.Date
     }
     )
    )
    

     

  • Community Power Platform Member Profile Picture
    on at

    Thanks @timl,

     

    It seems to be returning NULL for me. Not sure why. Any information I can provide that might make it easier to solve..?
    My data source is SQL and my date column is data type date.

  • timl Profile Picture
    36,393 Super User 2025 Season 2 on at

    Hi @Anonymous 

    Looking at this further, one thing I missed here was to sort the records by date descending order whilst retrieving the last record. Maybe this will work better for you.

    With(
     {lastRecord:
     First(FirstN(SortByColumns('[dbo].[Table]',"Date", Descending), 1))
     },
     Patch(
     '[dbo].[Table]',
     Defaults('[dbo].[Table]'),
     {
     Project: Gallery_overview.Selected.txtProjname.Text,
     Date:lastRecord.Date
     }
     )
    )

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hi @timl 

     

    This seems to work on the whole table, but only for one row.
    Something I think I forgot to mention and changed in my post is that you select a project based on another gallery, like this: 

    Project: SelProj.

    Looks like it is able to add the next month after the greatest month in my table, but looks like it keeps repeating that and does not filter on the selected project. 

    Powerapprookie2_0-1618826149888.png

     


    Sorry to bother you, but really appreciate the help!

  • Verified answer
    timl Profile Picture
    36,393 Super User 2025 Season 2 on at

    Hi @Anonymous 

    To take into account the project and to fix the month problem, this type of logic should take you closer:

     

    With(
     {lastRecord:
     LookUp(Filter(SortByColumns('[dbo].[Table]',"Date", Descending), 
     Project = Gallery_overview.Selected.txtProjname.Text
     )
     )
     },
     Patch(
     '[dbo].[Table]',
     Defaults('[dbo].[Table]'),
     {
     Project: Gallery_overview.Selected.txtProjname.Text,
     Date:
     DateAdd(
     Date(Year(lastRecord.Date),Month(lastRecord.Date),1),
     1,
     Months
     )
     }
     )
    )
    

     

  • Community Power Platform Member Profile Picture
    on at

    Great! added the project lookup in filter section as well and it worked just as wanted! thanks!

  • timl Profile Picture
    36,393 Super User 2025 Season 2 on at

    You're welcome @Anonymous, glad that worked for you.

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard