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 / How to use a Named For...
Power Apps
Unanswered

How to use a Named Formula to refresh a Collection?

(0) ShareShare
ReportReport
Posted on by 15

I've got a Collection that is currently created in OnStart, but that can be refreshed by the user clicking a button or a refresh icon. So I've currently got the ClearCollect() formula populated in 3 different places, and it's gotten a bit complex as it uses Filter() and AddColumns() and some other logic.

 

I'd like to NOT need to maintain this same logic behind 3 different controls (App.OnStart, Button.OnSelect, and Icon.OnSelect). I was hoping that Named Formulas would work for me. I've enabled the feature, put the logic into there as 

 

RefreshTestCollection = <copied logic>;
RefreshProdCollection = <copied logic>

But now I cannot for the life of me figure out how to execute those formules in OnStart and behind the button/icon controls. Any help is appreciated.

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @BEJONES 

    For other users, who want to use Named Formulas, they have to be activated in the Settings as it is not on by default.

    Then it will appear in the Apps dropdown on the left side of the screen. 

    Your formulas don't require an imperative like OnSelect any more.  They are declarative and you can just use the alias in your app. They recalculate like formulas in Excel.

  • BEJONES Profile Picture
    15 on at

    Yes, I've done that. I've got the Named Formula property visible and put in the formulas.

     

    Now I can't figure out the syntax to execute those formulas as they're just ClearCollect() functions - they don't return any result aside from the populated Collection

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @BEJONES 

    Please see the changes I made above and take a look at this blog post.  Basically you use the formulas instead of global variables and collections.

      https://michelcarlo.com/2022/09/22/how-to-use-power-apps-named-formulas-experimental-feature/ 

  • BEJONES Profile Picture
    15 on at

    Yeah. Read that blog.

     

    Basically in Formulas I have something like this (more complex, but same idea):

     

    RefreshProdCollection = ClearCollect(prodCollection,Filter(productionDataTable,Status=Status.productionDataTable.Active))

     

    Now in my Refresh icon, I want to do something like 

    RefreshProdCollection;
    or
    RefreshProdCollection();

     

    and have it execute that ClearCollect in the named Formula.

  • leonsig93 Profile Picture
    229 on at

    I've been using them quite a lot, really helps cut down on how many ClearCollects you need to add around your app.

    Just need to remove the ClearCollect piece, so:

    YourNamedFormulaName = Filter(
     productionDataTable,
     Status=Status.productionDataTable.Active
    )

    Then your refresh button's OnSelect just becomes:

    Refresh(productionDataTable).

     

    Hope that helps!

  • TB-13091842-0 Profile Picture
    140 on at

    I'm fairly new to named formulas, but my understanding is that they're for, in essence, constants. I wouldn't name one to the string to be used in a Refresh button; instead, I think you can just write the collection definition in all its complexity once. The normal function would be:

    ClearCollect(Collection, [criteria])

    where the criteria part has all your Filter() and AddColumns() statements. So just write your formula as:

    Collection = [criteria]

    Now, whenever the data on which the Collection is based changes, the Collection changes, automatically and without the need for a Refresh action.

  • leonsig93 Profile Picture
    229 on at

    Have you tested that out? I thought collections would always be static with that approach since you are never running the actual Collect part of that function more than once. That's why I used the refresh version thinking the collection would never update otherwise.

     

    Misread your reply. We currently use them in that fashion, the issue seems to be that the formula's won't auto update unless actions are taken within that user's session. For example, if I submit a new item via a form, User #2 doesn't see it in their "Today's Submissions" gallery. So we added the manual refresh button to make sure the users could have a way of forcing the refresh.

  • TB-13091842-0 Profile Picture
    140 on at

    Yes. I already had a collection based on underlying data. I made a TestCollection whose criteria statement was just ShowColumns(MainCollection, "ColumnName"). A gallery showed the TestCollection, and when I changed the underlying data and the TestCollection changed appropriately. It's the definition of the collection in App.Formulas that's static, not the content. (But, again, I'm speaking as an amateur. I don't guarantee this, but would love to hear if further testing doesn't bear it out.)

  • TB-13091842-0 Profile Picture
    140 on at

    Ah, yes, I see your issue. And yes, I see how that case would need the refresh. 

     

  • Toltekrom Profile Picture
    on at

    This topic was not "SOLVED" correct? I am having trouble just using formulas at all. I set the formula to replace a collection of distinct records, but the formula is empty when I add a listbox. 

    Toltekrom_0-1701267011959.png

    Also, I cannot Refresh(Formula)

    Toltekrom_1-1701267138223.png

     

     

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 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard