Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Trying to Filter a Gallery using LookUp function

Posted on by 359

I have a Gallery of data that is grouped on a field called Title and I am filtering on 2 date fields and a TextBox that allows filtering on licensee and/or authorisation - see below code

SortByColumns(
 AddColumns(
 GroupBy(
 With(
 {
 _preFilter: Filter(
 Claims,
 startdatetime >= DatePickerFrom_2.SelectedDate && enddatetime <= DatePickerTo_2.SelectedDate && (StartsWith(licensee,TextInput7_1.Text) || StartsWith(authorisation,TextInput7_1.Text)Or StartsWith(LookUp(Events,eventID=eventID,wma.Value),TextInput7_1.Text))
 )
 },
 If(
 !IsBlank(Searchbox_1.Selected.eventID),
 Filter(
 _preFilter,
 (eventID in Searchbox_1.SelectedItems.eventID)
 ),
 
 _preFilter
 )
 ),
 "Title",
 "Data"
),
"thewma",LookUp(Events,eventID=Text(First(Data).eventID),wma.Value),
"theeventid",First(Data).eventID, 
"licensee",First(Data).licensee,
"meterno",First(Data).meterno,
"startdatetime",First(Data).startdatetime,
"enddatetime",First(Data).enddatetime,
"startread",First(Data).startread,
"endread",First(Data).endread,
"dateentered",First(Data).dateentered,
"dateofform",First(Data).dateofform,
"MLcalculated",Sum((Data),MLcalculated),
"manualusage",First(Data).manualusage,
"comments",First(Data).comments
),
"licensee",SortOrder.Ascending)

I am trying to add another filter which involves a LookUp to a different Sharepoint list and this is the one I can't get to work

The code should LookUp eventID from the Events list and match it with eventID from the Claims list and return the wma value from the Events list so it can be searched on (StartsWith....)

 

In the AddColumns section of my code I have successfully added "thewma" column using a LookUp function but when I try a similar approach in the Filter section it fails with "Fetching items failed, possible invalid string in filter query"

 

I am missing something obvious I think - could someone point me in the right direction please?

thanks

 

Categories:
  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to Filter a Gallery using LookUp function

    thanks @WarrenBelz 

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 143,487 on at
    Re: Trying to Filter a Gallery using LookUp function

    @bobgodin ,

    You have left out two brackets, which are important to separate and/or sets - I posted

    (
     Len(Searchbox_1.Selected.eventID) = 0 ||
     eventID in Searchbox_1.SelectedItems.eventID
    ) &&
    TextInput7_1.Text in IDEvent

    and you have

    Len(Searchbox_1.Selected.eventID) = 0 ||
    EventID in Searchbox_1.SelectedItems.eventID &&
    TextInput7_1.Text in IDEvent

    you might check this is actually getting the result you require.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to Filter a Gallery using LookUp function

    Hi @WarrenBelz sorry for the tardy response....I just moved a couple of brackets around and got it working:

    GroupBy(		 
     Filter(
     AddColumns(
     _preFilter,
     "IDEvent",
     LookUp(
     Events As _Event,
     _Event.eventID = eventID)
     .wma.Value
     ),
     
     Len(Searchbox_1.Selected.eventID) = 0 ||
     eventID in Searchbox_1.SelectedItems.eventID
     &&
     TextInput7_1.Text in IDEvent
     ),
     "Title",
     "Data"
     ),
     "_ID",
     First(Data).ID
     )
     },
     Filter(
     _preFilter,
     ID in _Grouped._ID
     )
     )
    )

    thanks very much for the assistance as always 🙂

  • WarrenBelz Profile Picture
    WarrenBelz 143,487 on at
    Re: Trying to Filter a Gallery using LookUp function

    @bobgodin ,

    Is EventID the same data type in both lists or is it a Number in Claims and Text in Events ?

    . . . . . 
    AddColumns(
     _preFilter,
     "IDEvent"
     LookUp(
     Events As _Event,
     _Event.EventID = Text(EventID)
     ).wma.Value
    ),
    . . . . . .

    Also any error messages are hugely helpful in trying to debug issues with code of this size - I have run it here on a couple of test lists with the same field types and it is valid code.

     

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to Filter a Gallery using LookUp function

    Hi @WarrenBelz - I have added a couple of commas and nearly there I think:

    bobgodin_0-1704682637529.png

    could you help me out with the last little bit please?

  • WarrenBelz Profile Picture
    WarrenBelz 143,487 on at
    Re: Trying to Filter a Gallery using LookUp function

    HI @bobgodin ,

    Just missing a couple of commas (challenge of keeping brain fully engaged when free-typing large chunks of code . . .) - I thought you might have spotted them.

  • bobgodin Profile Picture
    bobgodin 359 on at
    Re: Trying to Filter a Gallery using LookUp function

    Hi @WarrenBelz thanks for your prompt response - however it's not quite working from about halfway down the code - see screenshot...

    bobgodin_0-1704678935648.png

    any ideas?

    thanks

  • Verified answer
    WarrenBelz Profile Picture
    WarrenBelz 143,487 on at
    Re: Trying to Filter a Gallery using LookUp function

    Hi @bobgodin ,

    You also have a Delegation issue there with the relational lookup. Try this for a start

    SortByColumns(
     AddColumns(
     GroupBy(
     With(
     {
     _preFilter: 
     Filter(
     Claims,
     startdatetime >= DatePickerFrom_2.SelectedDate && 
     enddatetime <= DatePickerTo_2.SelectedDate && 
     (
     StartsWith(
     licensee,
     TextInput7_1.Text
     ) || 
     StartsWith(
     authorisation,
     TextInput7_1.Text
     ) 
     )
     )
     },
     Filter(
     AddColumns(
     _preFilter,
     "IDEvent",
     LookUp(
     Events As _Event,
     _Event.EventID = EventID
     ).wma.Value
     ),
     (
     Len(Searchbox_1.Selected.eventID) = 0 ||
     eventID in Searchbox_1.SelectedItems.eventID
     ) &&
     TextInput7_1.Text in IDEvent
     ),
     "Title",
     "Data"
     ),
     "thewma",
     First(Data).IDEvent,
     "theeventid",
     First(Data).eventID, 
     "licensee",
     First(Data).licensee,
     "meterno",
     First(Data).meterno,
     "startdatetime",
     First(Data).startdatetime,
     "enddatetime",
     First(Data).enddatetime,
     "startread",
     First(Data).startread,
     "endread",
     First(Data).endread,
     "dateentered",
     First(Data).dateentered,
     "dateofform",
     First(Data).dateofform,
     "MLcalculated",
     Sum(Data,MLcalculated),
     "manualusage",
     First(Data).manualusage,
     "comments",
     First(Data).comments
     ),
     "licensee",
     SortOrder.Ascending
    )

    also I cannot test this, but may be a less complex approach to adding all those fields back

    With(
     {
     _preFilter:
    	 SortByColumns(
     Filter(
     Claims,
     startdatetime >= DatePickerFrom_2.SelectedDate && 
     enddatetime <= DatePickerTo_2.SelectedDate && 
     (
     StartsWith(
     licensee,
     TextInput7_1.Text
     ) || 
     StartsWith(
     authorisation,
     TextInput7_1.Text
     )
     )
     ),
     "licensee",
     SortOrder.Ascending
     )
     },
     With(
     {
     _Grouped:
     AddColumns(
     GroupBy(		 
     Filter(
     AddColumns(
     _preFilter,
     "IDEvent",
     LookUp(
     Events As _Event,
     _Event.EventID = EventID,
     ).wma.Value
     ),
     (
     Len(Searchbox_1.Selected.eventID) = 0 ||
     eventID in Searchbox_1.SelectedItems.eventID
     ) &&
     TextInput7_1.Text in IDEvent
     ),
     "Title",
     "Data"
     ),
     "_ID",
     First(Data).ID
     )
     },
     Filter(
     _preFilter,
     ID in _Grouped._ID
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard