cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jup
Helper II
Helper II

Problem with SQL Query - Lookup funktion in Gallery (AddColumns)

Hi all!

 

my problem:

 

I want to create a gallery with a lookup (join) on 2 tables.

 

My 1st szenario works fine:

 

2.PNG1.PNG

 

As you can see: In the gallery the values from both tables are shown correctly ([TestUser].[name] -and- [TestCostCenter].[Caption].

I used "ThisItem.TestUserRecord.Caption" for the label.

----------------------------

BUT... my 2nd szenario doesn't show the value from the lookup-Table (it's blank and I dont know why):

3.PNG

Here I'll get the items from the table [StockItem] but the values from the table [StockType] is BLANK (???!!!).

I used "ThisItem.StockItemRecord.Caption" for the label.

-----------

The table structure in both szenarios are the same. (Primary Keys...)

The only difference is that in szenario 1 (working szenario) there are only a few records in the both tables.-In szenario 2 (not working - blank items) there are >1000000 items in the tables.

 

Is this a delegation-problem?

please help.

 

thanks

jup

1 ACCEPTED SOLUTION

Accepted Solutions

Although the abbreviated form worked for my little test sample, you might want to go fully qualified on the names.

 

AddColumns('[dbo].[TestUser]',
      "CostCenterName", Lookup('[dbo].[TestCostCenter]', '[dbo].[TestCostCenter]'[@IdCostCenter]='[dbo].[TestUser]'[@IdCostCenter]).Caption)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

14 REPLIES 14
jup
Helper II
Helper II

Can anyone help me? I do not understand the JOIN of 2 tables and never get the desired result on a gallery.

That can not be that hard or right ?!

Are there any prerequisites for the database (onpremise mssql tables) ?!

I do not understand that... 😕 *crying*

@jupnot entirely sure why you would want to bring in the full record of the CostCenter table into your current gallery list.  It seems (from what I see) that you have a list of items from the User table.  What else would you want there from the CostCenter table??  And, as I see the screen, you have the ">" navigation that would presumably take you to another screen (or other) that would have the list of looked up items from the CostCenter table in it.

 

So...with that said - trying to elliminate a large pull of data and memory usage when not needed, I believe you might simply be needing the cost center name.

  AddColumns('[dbo].[TestUser]', "CostCenterName", Lookup('[dbo].[TestCostCenter]', IdCostCenter=IdCostCenter)

 

As for the Stock Items - I am not sure what your tables look like.  You didn't supply the info for them.  I assume they are pretty much the same and the logic above should work there too.

 

I don't have the spare time at the moment to do some tests for you, but if you don't figure it out and no one else helps, I'll check on it later.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Thank you for your response!

 

If I use your formula

AddColumns('[dbo].[TestUser]'; "CostCenterName"; LookUp('[dbo].[TestCostCenter]'; IdCostCenter=IdCostCenter))

I get the following (wrong) result:

 

4.PNG

 

It has to be:

----

JOHN

Warehouse

----

Rick

IT

----

 

Thanks in advance

jup

NigelP
Kudo Kingpin
Kudo Kingpin

Hi @jup

 

1.Is this correct ?    the same variable both sides of the "=" sign  - IdCostCenter=IdCostCenter))

2. Dont you need a ShowColumns somewhere ShowColumns(AddColumns( etc etc?

 

Regards

 

Nigel

Yeah. I'll check into it in a bit. I'm out of touch for the next few hours.
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Sorry, been a bit rushed today.  Looking back at the stuff I sent before...

 

Here is what I was aiming for:

   AddColumns('[dbo].[TestUser]',
      "CostCenterName", Lookup('[dbo].[TestCostCenter]', [dbo].[TestCostCenter][@IdCostCenter]=IdCostCenter).Caption)

 

This will give you a datasource for your gallery that is the TestUser records with an added field of CostCenterName that comes from the TestCostCenter Caption field.

For the label in your gallery, your text would be ThisItem.CostCenterName

 

Hope that is clearer and helps.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

I really dont understand it. 

 

see the picture attached 😞

Although the abbreviated form worked for my little test sample, you might want to go fully qualified on the names.

 

AddColumns('[dbo].[TestUser]',
      "CostCenterName", Lookup('[dbo].[TestCostCenter]', '[dbo].[TestCostCenter]'[@IdCostCenter]='[dbo].[TestUser]'[@IdCostCenter]).Caption)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Thanks so much my friend! 

You solved my problems 🙂

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (1,468)