Let’s say you want to make a collection of Hashtags used in a certain Text Input control. Here’s how you do it using the HashTags() function in Power Apps.
Let me demonstrate it quickly below!
Using HashTags() function
Now, let’s consider the below scenario where you want to collect the Hastags from a Text Input and later on use business logic on that.
- As an example, let me take a Description multi-line text field on the Canvas App and I’ll also take a DataTable to show the collected Hashtags in the same.
I’ve renamed the Text Input to “Description”
- Now, to scan for hashtags and collect them, I’m writing the below formula on the OnChange operation of thee Text Input so that once I finish writing and move the focus away from Text Input, the Formula can scan for Hashtags and populate the collection.
- Now, here’s the formula I’ve used to scan the Text (String) for Hashtags present.
Microsoft Docs Link for HashTags() formula –
Why ClearCollect instead of Collect? – Because only using Collect will scan the field and add all the hashtags again causing redundancy.
Why I used Collection? – I could also use this collection elsewhere instead of directly assigning the above formula to the Items of the Data Table. Hence, the preference to use ClearCollect.
- Now, from the Data Table perspective, I’m simply populating the Data Table with the Collection [hashtagCollection] as the Data Source and make sure you also add the Result column as well, else, the Data Table will be blank even if the Collection is being populated.
Let’s see how the table will be populated as we Run the App.
- Now, I’ve written as Hello #PowerPlatform and moved the focus out of the Text Input, the Data Table (via Collections) is populated with the results.
- Again, if I add another Hashtag i.e. #PowerApps, it’ll add to the collection (Basically, erase everything and scan all over again behind the scenes)
To demonstrate this example, I’ve created a YouTube video for the same, kindly check it out!
Hope this was useful. Here are some more Power Apps / Power Platform posts you might want to check out –
- Rich Text Control for Canvas and Model-Driven App | Quick Tip
- Setting Correct Default Mode for Forms in a Canvas App | [Quick Tip]
- Rating Control to represent data from Dataverse in a Canvas Power App | Power Platform
- Clear a field value & Reset Form in a Canvas Power App [Quick Tip]
- Implement real-time search in Gallery of CDS records in a Canvas Power App | Power Platform
- Implement character length validation in a Canvas Power App | Power Platform
- Implementing Exit app, Logout and Confirm Exit features in a Canvas Power App
- Debug Published Canvas Power App with other users using Monitor | Power Platform
- AddColumns() function to dynamically add columns to a Data table in Canvas Power App | SharePoint List
- Log Canvas Power App telemetry data in Azure Application Insights | Power Apps