Ok, so I've been trying to solve this on my own, lots of helpful posts in here but can't seem to make it work.
I need help adding a column to a Sharepoint list through Powerapps. I have tried with AddColumns and can't seem to make it work. Might be the syntax, but no errors are showing up, it just doesn't work. Help please.
I have 3 sharepoint lists with this content:
List 1: Employees
-----------------
Employee
-----------------
Joe
Mary
Tom
List 2: Sales
----------!------------!------------
Salesman ! SaleDate ! Amount
----------!------------!------------
Joe ! 7/20/2017 ! 100
Joe ! 7/21/2017 ! 50
Tom ! 7/21/2017 ! 75
Joe ! 7/21/2017 ! 150
Mary ! 7/22/2017 ! 125
Joe ! 7/22/2017 ! 25
***Salesman is a lookup column that references List 1
List 3: Quotas
----------!------------!-----------
Person ! Date ! Quota
----------!------------!-----------
Joe ! 7/20/2017 ! 100
Joe ! 7/21/2017 ! 150
Tom ! 7/21/2017 ! 75
Joe ! 7/22/2017 ! 50
Tom ! 7/22/2017 ! 50
Mary ! 7/22/2017 ! 25
***Person is a lookup column that references List 1
So through Powerapps, I want to add a column to List 3, that adds up the total for the day for that employee from the data of List 2, and shows it up in a column named Total in List 3. That way I can use it to calculate how much has been done for the day for all employees, how much is missing for the quota or how much did they exceeded it by. With the added column, I want List 3 to look like this:
----------!------------!----------!------------
Person ! Date ! Quota ! Total
----------!------------!----------!------------
Joe ! 7/20/2017 ! 100 ! 100
Joe ! 7/21/2017 ! 150 ! 200
Tom ! 7/21/2017 ! 75 ! 75
Joe ! 7/22/2017 ! 50 ! 25
Tom ! 7/22/2017 ! 50 ! 0
Mary ! 7/22/2017 ! 25 ! 125
This I can then display in a BrowseGallery.
I have tried this:
AddColumns(List3;"Total";Sum(Filter(List2;Salesman.Value=Person.Value;DateValue(SaleDate)=DateValue(Date));Amount))
However this doesn't work. When I display List3 in a BrowseGallery everything is blanked out.
Don't know what I am doing wrong. Please help.
Thanks!
-Rafael C.
Solved! Go to Solution.
Forget what I just wrote, it wouldnt work because it would not show quotas with 0 sales.
I think you may need to look at these parts in red:
AddColumns( List3; "Total"; Sum( Filter(List2; Salesman.Value=Person.Value; DateValue(SaleDate)=DateValue(Date) ); Amount) )
Are SaleDate and Date validated as text or dates? You might be able to get away with not using DateValue if they are Dates already.
You are absolutely right, DateValue(Date) was the problem.
I found out that Salesman and Person DO need the .value
Also, one thing that I forgot to say was that SaleDate was calculated from the Sharepoint List (don't ask me why). So the DateValue(SaleDate) WAS needed, however Date was just a date, so it didn't need the DateValue(Date). That was the whole problem.
Just for the record, the actual working formula was the following:
AddColumns( List3; "Total"; Sum( Filter(List2; Salesman.Value=Person.Value; DateValue(SaleDate)=Date ); Amount) )
Thanks!
Hi Carmiol,
Please check this thread about “AddColumns not working with collection” for a reference:
https://powerusers.microsoft.com/t5/PowerApps-Forum/AddColumns-not-working-with-collection/m-p/29072...
@mr-dang's post could be a good explanation on this issue. AddColumns is not an 'active' action--it is temporarily applied (unless its result is collected, in which case the collection maintains the column).
Best regards,
Mabel Mao
Hi,
I think you may benefit from using the GroupBy() function. It looks at all of your records and groups them by distinct values in a column that you choose. You will need to nest one GroupBy into another.
Original formula with formatting:
AddColumns( List3; "Total"; Sum( Filter(List2; Salesman.Value=Person.Value; DateValue(SaleDate)=DateValue(Date) ); Amount) )
The formula below groups records: first--all records with the same date; then all records of the same date from the same person. I am doing everything around List2 since it is your raw data source.
GroupBy( GroupBy( List2; "SaleDate","SaleDate_1"), "Salesman","Salesman_1", )
Now that you have the subsets of data you want, you can add a helper column with AddColumns:
AddColumns( GroupBy( GroupBy( List2; "SaleDate";"SaleDate_1"); "Salesman";"Salesman_1" ), "Total";Sum(Salesman_1,Amount) )
This formula takes a Sum of the subset of each seller on each date.
Finally, you can add another helper column to look up the quota for that day and that person from List3.
AddColumns( GroupBy( GroupBy( List2; "SaleDate";"SaleDate_1"); "Salesman";"Salesman_1" ), "Total";Sum(Salesman_1,Amount); "Quota";First(Filter(List3;Person.Value=Salesman.Value;DateValue(Date)=DateValue(SaleDate))).Quota )
I have to double check that last part colored in magenta--I'm not exactly sure which columns can be referenced from the grouped data, but it has the right idea.
Or you could invert it to be like your original formula in which you do everything around List3 instead of List2.
Forget what I just wrote, it wouldnt work because it would not show quotas with 0 sales.
I think you may need to look at these parts in red:
AddColumns( List3; "Total"; Sum( Filter(List2; Salesman.Value=Person.Value; DateValue(SaleDate)=DateValue(Date) ); Amount) )
Are SaleDate and Date validated as text or dates? You might be able to get away with not using DateValue if they are Dates already.
You are absolutely right, DateValue(Date) was the problem.
I found out that Salesman and Person DO need the .value
Also, one thing that I forgot to say was that SaleDate was calculated from the Sharepoint List (don't ask me why). So the DateValue(SaleDate) WAS needed, however Date was just a date, so it didn't need the DateValue(Date). That was the whole problem.
Just for the record, the actual working formula was the following:
AddColumns( List3; "Total"; Sum( Filter(List2; Salesman.Value=Person.Value; DateValue(SaleDate)=Date ); Amount) )
Thanks!
I'm glad it worked out and in a simple way--I was taking things in a complicated direction.