cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
John_P
Level: Powered On

Filtering a CDS by Status in ClearCollect

This feels like something that should be straightforward, but I'm struggling with it. I'm using ClearCollect to create a Collection from a CDS entity. However, I just want the active records as I've no need to be storing the inactive ones. 

 

Filter(Sites,Text(statecode)="Active") works but gives me the delegation warning. I can't help feeling that must be a neater way to just query the 0 or 1 value of the status rather than getting the text value of the statecode. If there's a better way, then this might help me avoid the delegation warning too.

 

Just for context, here is the full command - 

ClearCollect(SitesLocal,AddColumns(Filter(Sites,Text(statecode)="Active"),"Site Name","str_name","Site Status",Status,"Site Manager Email",'Site Manager'.emailaddress1,"Contracts Manager Email",'Contracts Manager'.emailaddress1));

 

Is there a cleaner way to filter out the inactive records?

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Filtering a CDS by Status in ClearCollect

Hi @John_P ,

The reason why you get delegation warning is that the Text function is non-delegable function in CDS.

I've made a similar test.

Try this formula:

Filter(table,Status='Status (table)'.Active)

Here's a doc about delegable funtion in CDS for your reference:

https://docs.microsoft.com/en-us/connectors/commondataservice/

 

Best regards,

Community Support Team _ Phoebe Liu

 

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.
3 REPLIES 3
Super User
Super User

Re: Filtering a CDS by Status in ClearCollect

Hi @John_P 

I don't think that you can avoid the delegation warning because Status (or statecode) is a compound field.  Intellesense did not expose any properties of the Status field like ".Value". However, in Model Driven Apps, it is easy to filter Active from InActive records using metadata alone.  That being said, 

I was playing around with it and I found that if you add a column to your collection

ClearCollect(colplans,AddColumns(Plans,"stat",Status))

and then set the Items property of a DataTable or Gallery to 

Filter(colplans,"Active" in stat)

There was no delegation warning.

Community Support Team
Community Support Team

Re: Filtering a CDS by Status in ClearCollect

Hi @John_P ,

The reason why you get delegation warning is that the Text function is non-delegable function in CDS.

I've made a similar test.

Try this formula:

Filter(table,Status='Status (table)'.Active)

Here's a doc about delegable funtion in CDS for your reference:

https://docs.microsoft.com/en-us/connectors/commondataservice/

 

Best regards,

Community Support Team _ Phoebe Liu

 

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.
John_P
Level: Powered On

Re: Filtering a CDS by Status in ClearCollect

Thank you Phoebe Liu - that revised formula worked perfectly. Smiley Happy

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Users Online
Currently online: 42 members 4,530 guests
Recent signins:
Please welcome our newest community members: