cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stephenkln
Resolver I
Resolver I

If item exists in table 1 that is related to table 2, then true else false

Hey guys,

 

I need some help with an IF statement. Here is the context:

 

My app is connected to a sql db. I have a sql view that pulls the most recent records for each employee.

 

That view is displayed as a viewable form in powerapps and filtered based on the selected employee in the employee gallery. 

 

The view contains a global unique identifier for each record. I'll call this Table 1 for simplicity.

 

Table 1

 
EmployeeIdLastTrainingDateTrainingRowGuid
19/11/2020xxx-xxxx-xxxx-xxx

 

I have another view that contains a list of filenames that may or may not have a global unique identifier that relates to a record in Table 1. I'll call this Table 2.

 

Table 2

 
IdFileNameEmployeeIdAttachToId
1somefilename.docx1xxx-xxxx-xxxx-xxx
2anotherfilename.docx1NULL

 

What i'm trying to do is display an icon next to the relevant Table 1 item in my powerapps form if there is an associated file attached, which would be indicated if there was a matching global unique identifier.

 

So that gets to the formula, the formula should toggle the visible properties of the icon. Here is what i was trying to use to accomplish this:

 

If(CountRows(Filter('[Table 2]',EmployeeId='Employee Gallery'.Selected.EmployeeId,AttachToId=LookUp('[Table 1]',EmployeeId='Employee Gallery'.Selected.EmployeeId).TrainingDateRowGuid))>0,true,false)

 

I have this on the icon's visible property, but I'm having multiple problems. First I'm getting a delegation warning. And second it is displaying the icon when there is no related file. 

 

Any ideas on how i could go about fixing this?

 

Let me know if further explanation is required.

 

Thanks!

 

13 REPLIES 13
yashag2255
Dual Super User II
Dual Super User II

Hi @stephenkln 

 

Can you try to update the expression to:

If(CountRows(Filter('[Table 2]',EmployeeId='Employee Gallery'.Selected.EmployeeId && AttachToId='Employee Gallery'.Selected.TrainingDateRowGuid))>0,true,false)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255, thanks for the response. This doesn't quite work because the Employee Gallery is based on a different table and does not contain the rowguid column.

 

Employee Gallery = Table 3 (employees table)

Form = Table 1 (most recent records by employee table with rowguid)

 

Table 2 contains all files and any related rowguid

 

All three tables contain employeeid, but only table 1 and 2 have the rowguid.

 

Hi @stephenkln 

 

In that case, the formula shared by you seems correct.

If(CountRows(Filter('[@Table 2]',EmployeeId='Employee Gallery'.Selected.EmployeeId && AttachToId=LookUp('[Table 1]',EmployeeId='Employee Gallery'.Selected.EmployeeId).TrainingDateRowGuid))>0,true,false)

 

I am assuming that you have applied this formula outside of 'Employee Gallery'. If this is not the case, then update the formula to: 

If(CountRows(Filter('[@Table 2]',EmployeeId=ThisItem.EmployeeId && AttachToId=LookUp('[Table 1]',EmployeeId=ThisItem.EmployeeId).TrainingDateRowGuid))>0,true,false)

 

Can you do a test on your side?

1) Add a test button as a child item inside gallery.

2) Set the OnSelect property of the button to: ClearCollect(MyTestCollection, Filter('[@Table 2]',EmployeeId='Employee Gallery'.Selected.EmployeeId && AttachToId=LookUp('[Table 1]',EmployeeId='Employee Gallery'.Selected.EmployeeId).TrainingDateRowGuid))

3) Check if it is returning proper values.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 Testing with the button and collection returned the correct value.

 

But when I use this formula outside the gallery, I get delegation warnings and it does not perform correctly. The icon is visible when it should not be.

@stephenkln 

 

What is the Items property of the Gallery control? Can you share a screenshot of the configuration so that we might be able to help you better.

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 this is what is in the items property of the gallery:

 

If(Or(SearchBox.Text=Blank(),SearchBox.Text=""),Sort('[EmployeesTbl]',LastName,Ascending),Search('[EmployeesTbl]',SearchBox.Text,"LastName","FirstName","FullName"))
 
screenshot.png

@stephenkln 

 

can you update the expressions to:

 

If(!IsBlank(SearchBox.Text),Sort('[EmployeesTbl]',LastName,Ascending),Search('[EmployeesTbl]',SearchBox.Text,"LastName","FirstName","FullName"))

 

Icon Visibility: If(CountRows(Filter('[@Table 2]',EmployeeId=ThisItem.EmployeeId && AttachToId=LookUp('[Table 1]',EmployeeId=ThisItem.EmployeeId).TrainingDateRowGuid))>0,true,false)

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

@yashag2255 I updated the gallery items formula. I cannot update the formula on the visible property of the icon to the one you just suggested because I cannot use the ThisItem property. Note that the icon is not part of the gallery. The icon is on the screen with the gallery, but it is not a child in the gallery.

@stephenkln 

 

Can you try to update the expression to:

If(IsEmpty(Filter('[@Table 2]',EmployeeId='Employee Gallery'.Selected.EmployeeId && AttachToId=LookUp('[Table 1]',EmployeeId='Employee Gallery'.Selected.EmployeeId).TrainingDateRowGuid)),false, true)

 

Also, can you try to clear the cache of your browser?

 

Hope this Helps!

 

If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (14,912)