web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Using ClearCollect() w...
Power Apps
Unanswered

Using ClearCollect() within an If function?

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

Are we allowed to use the ClearCollect( Collection, Item, ... ) function within If( Condition, ThenResult [, DefaultResult ] ) functions?

 

I'm able to use the Kusto Connector successfully within a ClearCollect function from a gallery's OnSelect property; but when I try to wrap it inside an If function to avoid unnecessary calls to Kusto, clicking on "Capture Schema" does nothing. Moving it back outside the If function allows it to work again.

 

I really would like to avoid making any unnecessary calls to Kusto if I can avoid them, and this is my first approach.

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,024 Most Valuable Professional on at

    @MTv 

    Can you please share the code that is not working.

  • MTv Profile Picture
    Microsoft Employee on at

    # sorry for the lack of formatting....
    # columns and values changed to protect the innocent ^^ 😎

     

    If(
    ThisItem.Category = "International",
    ClearCollect(
    InternationalCollection,
    AzureDataExplorer.listKustoResultsPost(
    "https://***.kusto.windows.net",
    "***",
    "Dim_***() | where Id == '" & ThisItem.Name & "'"
    ).value)
    );
    If(
    ThisItem.Category = "Domestic",
    ClearCollect(
    DomesticCollection,
    AzureDataExplorer.listKustoResultsPost(
    "https://***.kusto.windows.net",
    "***",
    "Dim_Customer***() | where Id == '" & ThisItem.Name & "'"
    ).value)
    );

     

  • WarrenBelz Profile Picture
    153,024 Most Valuable Professional on at

    @MTv ,

    I thought you were referring to a Power Apps collection - what is this bit for

    AzureDataExplorer.listKustoResultsPost( . . . .

    also the code is not PowerFX - it looks more like SQL

  • Community Power Platform Member Profile Picture
    on at

    Hello @MTv 

     


    Here is a working a record in a power app collection=>

    If( LookUp(Employee3; ID=ThisItem.ID).ID >0;
    RemoveIf(Employee3; ID=ThisItem.ID);
    Collect(Employee;ThisItem)
    )
    if the record is found in the collection then remove it, otherwise put it in the collection.

     

     

    Thank You

     

  • MTv Profile Picture
    Microsoft Employee on at

    I am using a PowerApps collection. That's using the PowerApps' Kusto Connector to populate the Collection.

  • Verified answer
    v-jefferni Profile Picture
    on at

    Hi @MTv ,

     

    You may try it with the Switch function:

    Switch(
     ThisItem.Category, 
     "International",
     ClearCollect(
     InternationalCollection,
     AzureDataExplorer.listKustoResultsPost(
     "https://***.kusto.windows.net",
     "***",
     "Dim_***() | where Id == '" & ThisItem.Name & "'"
     ).value
     )
     "Domestic",
     ClearCollect(
     DomesticCollection,
     AzureDataExplorer.listKustoResultsPost(
     "https://***.kusto.windows.net",
     "***",
     "Dim_Customer***() | where Id == '" & ThisItem.Name & "'"
     ).value
     )
    );

     

    Hope this helps.

     

    Best regards,

    Community Support Team _ Jeffer Ni
    If this post helps, then please consider Accept it as the solution to help the other members find it.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 793 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard