I am having a heck of a time trying to understand the syntax of powerapps.
I have a background in SQL and I am very comfortable with it. This is not SQL :(.
I have an SQL database. My SQL database was built correctly, with the min amount of repeating data. It seems like Powerapps wants me to have 1 giant table with everything on it instead of multiple tables that are related and joined.
Here is what I need to understand:
Example - I have 3 tables with information I need from each in a gallery.
Table 1 - UPC_Details
Columns (UID) UPC_ID, Brand_ID, Cost, Created_Date
Table 2 - Brand_ID
Coulmns (need to join to UPC_Details Brand_ID) (UID) Brand_ID, Brand_Name, Company_Contact_ID...
Table 3 - UPC_received
Columns (UID) UPC_Received_ID, (need to join to table UPC_Details so users know what item they are looking at when the UPC is scanned) UPC_ID, Cases_received, Date_received...
I am sure you can see where this is going.
I need my users to be able to see specific data that I normally would use a join to reference. I do not know if I should be building a collection onvisble, or something else entire. Nor do I undertand the syntax Powerapps uses. I am extremely dissapointed with the resources for Powerapps, as I do not feel these questions are well answered and I am sure I am not the only user with this problem.
Thank you in advance to anyone willing to help me out with this.
Solved! Go to Solution.
You can use the functions AddColumns and LookUp to perform joins in PowerApps. Taking the example from W3Schools, where we have two tables:
Orders
OrderID CustomerID OrderDate 10308 2 1996-09-18 10309 37 1996-09-19 10310 77 1996-09-20
Customers
CustomerID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico
To generate the result of the JOIN listed in that page:
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID
This would be a similar expression in PowerApps:
ShowColumns( AddColumns( Orders, "CustomerName", LookUp(Customers, CustomerId = Orders[@CustomerId], CustomerName)), "OrderId", "CustomerName", "OrderDate")
You can also join the entire customer record, instead of only choosing a single column from that table. For example, if you have this expression in a button's OnSelect property:
ClearCollect(myCollection, AddColumns( Orders, "Customer", LookUp(Customers, CustomerId = Orders[@CustomerId])))
Then you can access the name of customer for the first order using:
First(myCollection).Customer.CustomerName
Or if you set the 'myCollection' to the Items property of a gallery, you can have a label within the gallery with the Text property set to
ThisItem.Customer.CustomerName
And it would show the customer name for that row in the (augmented) orders table.
Granted, I agree that a SQL join with all other niceties (grouping, native filtering, etc.) would be nice to have. There is an existing idea to support SQL queries (instead of simple tables) directly in the PowerApps Ideas board, please consider voting on it!
You can use the functions AddColumns and LookUp to perform joins in PowerApps. Taking the example from W3Schools, where we have two tables:
Orders
OrderID CustomerID OrderDate 10308 2 1996-09-18 10309 37 1996-09-19 10310 77 1996-09-20
Customers
CustomerID CustomerName ContactName Country 1 Alfreds Futterkiste Maria Anders Germany 2 Ana Trujillo Emparedados Ana Trujillo Mexico 3 Antonio Moreno Taquería Antonio Moreno Mexico
To generate the result of the JOIN listed in that page:
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID
This would be a similar expression in PowerApps:
ShowColumns( AddColumns( Orders, "CustomerName", LookUp(Customers, CustomerId = Orders[@CustomerId], CustomerName)), "OrderId", "CustomerName", "OrderDate")
You can also join the entire customer record, instead of only choosing a single column from that table. For example, if you have this expression in a button's OnSelect property:
ClearCollect(myCollection, AddColumns( Orders, "Customer", LookUp(Customers, CustomerId = Orders[@CustomerId])))
Then you can access the name of customer for the first order using:
First(myCollection).Customer.CustomerName
Or if you set the 'myCollection' to the Items property of a gallery, you can have a label within the gallery with the Text property set to
ThisItem.Customer.CustomerName
And it would show the customer name for that row in the (augmented) orders table.
Granted, I agree that a SQL join with all other niceties (grouping, native filtering, etc.) would be nice to have. There is an existing idea to support SQL queries (instead of simple tables) directly in the PowerApps Ideas board, please consider voting on it!
Hi @Mickell2030
Fully sympathise, it takes a few days to understand how PowerApps works, but then it will all be clear.
@CarlosFigueirais right in using LookUp, and another key to joining tables is the 'in' operator.
Please see this post of mine for example, just ignore the intro and go to the PowerApps expressions:
Other posts on my blog may also be of help, for examplein improving performance of lookups.
Comments/questions welcome.
thank you. You took the time to really detail it out and I get it. I want to love Powerapps because so many other things are simpler from a programming prospective. I sure do hope this will become a bit cleaner with time and that SQL can become integrated language. Until then, your explanation was the best I could have hoped for.
Hi
I am having nightmare joining two lists in my power app.
I have two lists.
List1 is called SalesOrders with colomns SalesOrderID, Customer, SalesPerson
List2 is called SalesGroups with colomns SalesPerson, Group
Now i want to join list1 and list2 with primary key as SalesPerson and get Group. i tried with above steps but couldnt make it to work.
Kindly help me on this.
Collect(List1Collection,AddColumns(List1,"Group",First(Filter(List2,SalesPerson=SalesPerson)).Group)
This will put it into a collection.
Havnt tested but you may need to use @ before 2nd salesperson or List1.SalesPerson, im not on the system at present and its been a while.
if you want to do it live within a gallery for instance you can set the gallery items to List1, then have a text box that just does: First(Filter(List2,SalesPerson=ThisItem.SalesPerson)).Group within each gallery item
I find First(Filter)) works faster than Lookup() but you can also use: Lookup(List2,SalesPerson=ThisItem.SalesPerson,Group)
Thank you for the response.
I tried with the above but still i have no luck.
Hi all.
I've got 2 joined tables with that syntax:
ShowColumns(AddColumns('[SIE].[DatosGenerales]';"Denominacion";LookUp('[Dim].[DimSIE]'; DimSIEId = '[SIE].[DatosGenerales]'[@DimSIEId]; Denominacion));"Denominacion";"DimSIEId";"ModificadosMesActual";"PresupuestoInicialMesActual";"TrabajosATercerosMesActual";"RevisionDePreciosMesActual";"ComplementariosMesActual";"OtrosMesActual";"PresupuestoVigenteMesActual";"Mes")
It's just a table SIE.DatosGenerales and the column "Denominacion from DIM.DimSIE,but I want tomake a "Where" there to show only the rows I want. How can I do it?
Hope it can helps you.
LookUp only returns the first record that is matched. What if there are multiple records to match? I'm guessing a Filter would do the trick. Is that right or is there a more efficient way?
User | Count |
---|---|
258 | |
110 | |
97 | |
57 | |
39 |