cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Samurai89
Level: Powered On

Adding new data to data source using a form

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:

 

EmployeeDetails.jpgData 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. 

ScreenNewHours.jpgScreenNewHours

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

MonthYear.jpgData source: MonthsDataEmployeeTable.jpgData source: EmployeeTableCategoryTable.jpgData 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! 

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

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. 

View solution in original post

13 REPLIES 13
Super User
Super User

Re: Adding new data to data source using a form

Hi @Samurai89,

There is no problem using multiple data sources to enter information into one table.  As long as you are only adding new records to your spreadsheet,  you can achieve your goal by using the Collect() function. (You would use a different function if you were editing data already in the table.)  Also, I would leave as little chance of the user entering text as possible, so for inputting data into the Category column, I would use a Dropdown control or Radio control with the Items property set to ["Lunch","Meetings","Work","Travel","Breaks"]. For the numeric entries, you might want to consider using a Slider control.  I've been burned in the past by user's entering data in unpredictable ways, like putting text in an Inputbox when a number is expected. 

Your Save button would have as it's OnSelect() property

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

In order for the Collect() function to work properly, The column names in the collect function must be identical to the column names in the data source.   The ID is entered using a calculation and would be invisible to the user. I like using First(Sort(Descending  instead of Max() or Last() because the latter are not delegatable and if the table grows to over 2000 records, those functions will not be correct while First(Sort(Descending  will work for very large tables. 

You could make sure that all required fields are entered by using the DisplayMode of the Save button to disable it until data was entered.  So if LeaveDays and TotalHours were required fields, the DisplayMode property of the button would be

If(!IsBlank(DataCardKeyTotalHours) && !IsBlank(DataCardKeyLeaveDays), DisplayMode.Edit, DisplayMode.Disabled)

 

Samurai89
Level: Powered On

Re: Adding new data to data source using a form

This information is really great, however, how can I enter data for all the categories at the same time and save it to the data source at once?

Samurai89
Level: Powered On

Re: Adding new data to data source using a form

I've applied these formulas as you suggested, however, I'm getting the following error:

Incompatible type: The 'DaysAtWork' column in the data source you're updating expects a 'Number' type and you are using a 'Error' type. 
The function 'Collect' has some invalid arguments.

 I get the same error for all the values, except the MonthYear and Employee drop-downs (Employee : DropdownEmployee.Selected.Employee and MonthYear : DropdownMonthYear.Selected.MonthYear).

I've checked the data source and these columns are all formatted as 'Number' type. 

Super User
Super User

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.
Samurai89
Level: Powered On

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?

Super User
Super User

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
Level: Powered On

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: 

EmployeeDetails.jpgData 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:

CategoryTable.jpgData 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?

 

Super User
Super User

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
Level: Powered On

Re: Adding new data to data source using a form

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

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 363 members 6,510 guests
Recent signins:
Please welcome our newest community members: