web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : YMZbSihrZjV6Bizffj5zFi
Power Apps - Building Power Apps
Answered

Adding new data to data source using a form

Like (0) ShareShare
ReportReport
Posted on 6 Dec 2018 13:21:16 by 36

Hello again,

 

I'm trying to create a form to add new employee work hours to an existing Excel data source. The data source (EmployeeDetails) has the following columns:

 

Data source: EmployeeDetailsData source: EmployeeDetails

I want a form that allows me to enter all this information at once for one employee, that is, select the month from a drop-down list, select the employee from a drop-down list, and enter the value for each category (Lunch, Meetings, Work, Travel, Breaks) in separate fields, etc. 

ScreenNewHoursScreenNewHours

I'm using different data sources to populate the MonthYear drop-down (DropdownMonthYear) and Employee drop-down (DropdownEmployee) and the Category information:

Data source: MonthsDataData source: MonthsDataData source: EmployeeTableData source: EmployeeTableData source: CategoryTableData source: CategoryTable

Basically, the form should let you select the MonthYear from a drop-down list, the Employee from a drop-down list (these work), to display each category and allow you to enter a value for each category, and at the end submit this all to the EmployeeDetails data source. Is this possible? Is it possible to add information from one data source to another data source?

 

Any help/advice would be appreciated! 

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on 21 Dec 2018 at 14:52:46
    Re: Adding new data to data source using a form

    Hi @Samurai89,

    You don't need a form or gallery to do what you want.  Since all of the items are entered once a month, change your Excel table to have them all in one row. Name the Table employeedata, 

     The HoursSpent column is calculated as shown in the box above the table.employeedata.PNG

     

     

    Take a blank screen and add a Dropdowns for Month and Year. Put the Labels, Dropdowns and Textinput controls on it as you have shown in your figure above. The Submit button should have as the OnSelect property, 

    Collect(employeedata, {ID: Last(employeedata).ID+1, Employee: Dropdown1.Selected.Value, Month: DropdownMonth.Selected.Value,
    Year: DropdownYear.Selected.Value, Lunch: Value(TextinputLunch.Text), Meetings: Value(TextInputMeetings.Text),
    Work: Value(TextInputWork.Text), etc.

    You can add another button to reset the controls to blank after you enter the data for each employee. 

  • Samurai89 Profile Picture
    36 on 21 Dec 2018 at 06:54:09
    Re: Adding new data to data source using a form

    Hi @Drrickryp,

     

    Thanks a lot for your email and your attached app. However, I'm trying to add new records, not edit existing ones:

     

    MainScreen.jpg

    This is what I'm trying to accomplish: Add all this information on one screen and add it all to the 'EmployeeDetails' table. The boxes next to the categories are for 'HoursSpent' values, and the 'TotalHours' value is calculated as the sum of all the entered 'HoursSpent' values. 

     

    The only way I figured out how to display all the categories at the same time is using a gallery, and then adding a Text input box next to them. I can format the text inputs as numerical values, but how do I save all this to my data source?

     

  • Samurai89 Profile Picture
    36 on 19 Dec 2018 at 06:16:39
    Re: Adding new data to data source using a form

    @Drrickryp Please find attached the Excel file with my data. In the meantime, I'll review Database-Design-Fundamentals-and-PowerApps-An-Overview. Thank you for your help.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 18 Dec 2018 at 19:09:20
    Re: Adding new data to data source using a form

    Hi @Samurai89

    Not necessary.  I'm suggesting in order to use best practices for creating your app, you will need 4 separate tables to describe what you have in the single spreadsheet table that you are currently using.  Each table must have an ID column (Primary Key) and in the case of the LeaveWork and TimeWorked tables, there would be a column for the Foreign keys of the other tables to create the relationships.  Please review my 4  posts in the Community blog to understand why this is desirable and why what you are doing with a single table is a poor design for an app. Please start with Database-Design-Fundamentals-and-PowerApps-An-Overview and then the three steps to building your tables in preparation for creating the app. In the meantime, could you post the excel file for your spreadsheet and I will help you out with it by recreating the tables that you can use in your app from the data you alread have.   

  • Samurai89 Profile Picture
    36 on 18 Dec 2018 at 18:56:29
    Re: Adding new data to data source using a form

    @Drrickryp I'm not sure I follow. Should I create/use a database file?

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 17 Dec 2018 at 16:15:27
    Re: Adding new data to data source using a form

    Hi @Samurai89,

    I was examining your data source table and in order to properly normalize it, I came up with the following tables.

    samurai.PNG The MonthYear and and MonthID can be calculated from the daterecorded and the total hrs worked can be calculated from the Sum(HoursSpent) so they don't need to be included in the underlying tables.

  • Samurai89 Profile Picture
    36 on 10 Dec 2018 at 05:41:53
    Re: Adding new data to data source using a form

    @Drrickryp I mean I would like to add a value for each category (Lunch, Meetings, Work, Travel, and Breaks), and every other column in this table: 

    Data source: EmployeeDetailsData source: EmployeeDetailsThe part I'm struggling with is adding a value for each category (Lunch, Meetings, Work, Travel, and Breaks) on the same form. I've also put the categories in a separate data source if that helps - CategoryTable:

    Data source: CategoryTableData source: CategoryTable

    So far I've managed to add a value for all the other columns:

    • Add a value for TotalHours (Completed)
    • Add a value for DaysAtWork (Completed)
    • Add a value for LeaveDays (Completed)
    • etc.

    The main goal is to save all these values at once to the same data source (EmployeeDetails). 

     

    How do I set it up to allow me to add a value for Lunch, Meetings, Work, Travel, and Breaks on the same form?

     

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 08 Dec 2018 at 16:11:18
    Re: Adding new data to data source using a form

    Hi @Samurai89,

    I am not sure what you mean by saving a record all at once.  Are you keeping the same record in different tables?  If so, this is a poor database design.  If one record can have many categories, and one category can have many records you are dealing with a Many-to-Many relationship and you will need to set up a junction table to handle it.  

  • Samurai89 Profile Picture
    36 on 08 Dec 2018 at 09:55:45
    Re: Adding new data to data source using a form

    Ok, so I did what you suggested and created a new screen. I had to change the OnSelect to:

    Collect(EmployeeDetails,{ID: First(Sort(EmployeeDetails,ID,Descending)).ID+1, 
    Employee: DropdownEmployee.Selected.Employee, MonthYear: DropdownMonthYear.Selected.MonthYear,
    LeaveDays: Value(DataCardKeyLeaveDays.Text), TotalHours: Value(DataCardKeyTotalHours.Text)})

    It kept showing errors for the DataCardKey values, so I figured out how to format them as values (based on the data card's default 'Update' value). Now it does not show any errors. However, I still need to find a way to add a value for each category and then save all this data at once. Any ideas? Is it possible to add a text input box for each category?

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on 07 Dec 2018 at 15:10:45
    Re: Adding new data to data source using a form
    Try this please. Start with a new screen and put fresh controls on it. Use the same formula for the save button but reference the new controls. Try it with one or two controls and if it works, add more. I’m unot sure what is wrong with your current form but rather than try to figure it out, I would start fresh.

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2