cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Problem with lookup fields - SQL Server as datasource

Hello Community,

I'm having a hard time while using Lookup formula. I have two tables in SQL Server. For  example:

Table 1

ItemID   ItemName   HasAvail

100         Shoes          F

101         Shirts           T

102         Cap              F

 

Table 2

ItemID   LocationID   Box_id    OnHand

100               1            600           50

100              43          601           20

 

I'm patching records into table 3. Here is the structure of it.

ItemID  ItemName   LocationID    Box_id    OnHand 

 

 

Here is my lookup formula, 

Patch(Table3,Defaults (Table3), Item ID: Value(Label1.Text),ItemName: Label2.Text,

Box_id: If(LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F"),First(Filter(Table2,Value(ID_Lbl.Text)= item_id && Loc_Lbl.Text = "43")).box_id,"0")

My Lookup formula fails to get the value of Box_id "601". It Patches "600" value in the table. How can this be fixed?

 

Please, help.. thank you!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Problem with lookup fields - SQL Server as datasource

Hi @bakgou1 ,

Firstly, the right syntax of if statement is:

If(condition,result1,result2)

The result of condition should be boolen.

While the formula that you use "LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F")" could only result a record or empty value, which is not boolen.

Please try this formula:

Patch(Table3,Defaults (Table3), {Item ID: Value(Label1.Text),ItemName: Label2.Text,
                                 Box_id: If(!IsEmpty(LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F")),
First(Filter(Table2,Value(ID_Lbl.Text)= item_id && Loc_Lbl.Text = "43")).box_id,"0")
}
)
//usually we use isempty to justify whether there a record that meets the requirments

Here are docs about if statement and isempty function for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-if

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Highlighted
Super User
Super User

Re: Problem with lookup fields - SQL Server as datasource

@bakgou1 

Your code is pretty complicated but getting "601" does not require much work.  Just change your FIRST function to LAST instead.

 

Patch(Table3,
Defaults(Table3),
{
ItemID:Value(Label1.Text),
ItemName:Label2.Text,
Box_id: If(LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F"),
Last(Filter(Table2,Value(ID_Lbl.Text)=ItemID && Loc_Lbl.Text = "43")).Box_id,
"0")
}
)

 

---
Please click "Accept as Solution" if my response helped to solve your issue so that others may find it more quickly. If your thought the post was helpful please give it a "Thumbs Up."

Highlighted
Community Support
Community Support

Re: Problem with lookup fields - SQL Server as datasource

Hi @bakgou1 ,

Firstly, the right syntax of if statement is:

If(condition,result1,result2)

The result of condition should be boolen.

While the formula that you use "LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F")" could only result a record or empty value, which is not boolen.

Please try this formula:

Patch(Table3,Defaults (Table3), {Item ID: Value(Label1.Text),ItemName: Label2.Text,
                                 Box_id: If(!IsEmpty(LookUp(Table1,Value(ID_Lbl.Text) = ItemID,HasAvail = "F")),
First(Filter(Table2,Value(ID_Lbl.Text)= item_id && Loc_Lbl.Text = "43")).box_id,"0")
}
)
//usually we use isempty to justify whether there a record that meets the requirments

Here are docs about if statement and isempty function for your reference:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-if

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (10,198)