cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Julien2
Post Prodigy
Post Prodigy

Removing last "," from the result without affecting what's selected

Hello everyone,

I am creating a canvas app, and in this app, I have a form that contains a gallery, inside this gallery I have a dropdown control, Save, Edit, and Delete icons.

On Visible of the screen I have a created a collection of two columns which is the below:

ClearCollect(ProductsOfInterest, {Products:"", ShowSave: true});

 In the dropdown, I have a list of products for example (Azure, Microsoft, Power Apps...), when the user clicks on save the same dropdown will be added to the collection in case he wants to select another product.

The Save select property:

Select(Parent);Patch(ProductsOfInterest, ThisItem, {Products:Dropdown3.Selected.Result, ShowSave:false});If(EditPressed,false,Collect(ProductsOfInterest, {Products: "", ShowSave:true}));

What I am trying to achieve is the following:
 I want to concatenate the products were stored in the collection results separated by "," into a text label.

In case, the user has deleted what he selected the text label should be updated based on what's is stored inside this collection

For example: let's say I have selected 2 items: M365, Microsoft
Then I have deleted M365 from the collection, then the final result should be "Microsoft". So the first item I select the "," should not appear until I select multiple values.

 

I have used the below function:

Concat(ProductsOfInterest.Products, Products,",")

But it shows: "M365," as a result knowing that it should be "M365" so the last "," character should be removed from the result.

I have also used this function:

Replace(Label2.Text,Len(Label2.Text),1,"")

But unfortunately, if I deleted twice from the collection the final result will be "M36" so the 5 is removed from the result I want to avoid this.
Capture.PNG

Can please someone explains in detail and provide an example to achieve the above scenario?

Any help will be greatly appreciated.

Thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
mdevaney
Super User
Super User

@Julien2 

Do you want to remove the last comma from your joined string?

 

With(
    {wString: Concat(ProductsOfInterest.Products, Products,",")},
    Left(wString, Len(wString)-1)
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

EricLott
Resident Rockstar
Resident Rockstar

@Julien2 

Is there a specific reason you are using a separate DropDown control to delete selected items from the other DropDown? You could use a ComboBox, which supports multiple selections natively.

Using a ComboBox with @mdevaney's solution should fix this.

Here are the docs for the ComboBox

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-combo-box

And if for some reason that still doesn't work, you can use a modified version of @mdevaney's solution like this

With(
    {wString: Concat(ComboBox1.SelectedItems.Value1, Value1,",")},
    If(Right(wString,1)=",",
    Left(wString, Len(wString)-1),wString)
)

View solution in original post

9 REPLIES 9
mdevaney
Super User
Super User

@Julien2 

Do you want to remove the last comma from your joined string?

 

With(
    {wString: Concat(ProductsOfInterest.Products, Products,",")},
    Left(wString, Len(wString)-1)
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

EricLott
Resident Rockstar
Resident Rockstar

The Concat() function should not be adding a final comma. See example below:

Can you post a screenshot with your Concat() formula in a label as a test?

paHelp.png

@EricLott 

Hey there buddy!  I show at comma at the end of my text string just like @Julien2 sees.  This also matches the official documentation for CONCAT. I wonder, are you using a newer version of PowerApps or a preview environment?  What’s your version #?

 

Link to CONCAT function documentation:

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-concatenate

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

EricLott
Resident Rockstar
Resident Rockstar

@mdevaney Hey hey!

That's interesting. I'm on 3.20074.20. I disabled all experimental and preview features and mine is still automatically omitting the last separator.

@EricLott 
I'm on a slight newer version 3.20089.20.  Can you create a blank new app and try the same function?  I wondering if what you were seeing was a regression.

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

EricLott
Resident Rockstar
Resident Rockstar

When I create a new blank app, it still runs on 3.20074.20. When I try to manually cut over to 3.20089.20 I get an error 🤔

Hello @mdevaney,

Thank you for providing an example.

I have tried the same function you mentioned, but unfortunately, if I have deleted more than 2 products the last character from the selected value/s will be deleted.

This is the delete icon on select property function:

Remove(ProductsOfInterest, ThisItem);

Please have a look at the demo below:
Demo.gif

Both labels Text properties functions: @EricLott 
Capture1.PNGCapture2.PNG
Looking forward to hearing from you!

Thanks again!

EricLott
Resident Rockstar
Resident Rockstar

@Julien2 

Is there a specific reason you are using a separate DropDown control to delete selected items from the other DropDown? You could use a ComboBox, which supports multiple selections natively.

Using a ComboBox with @mdevaney's solution should fix this.

Here are the docs for the ComboBox

https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/controls/control-combo-box

And if for some reason that still doesn't work, you can use a modified version of @mdevaney's solution like this

With(
    {wString: Concat(ComboBox1.SelectedItems.Value1, Value1,",")},
    If(Right(wString,1)=",",
    Left(wString, Len(wString)-1),wString)
)

Hello @EricLott ,

Yes, the reason is that we don't want to allow the employees to select multiple items.

The example you've provided has returned the result I want.

Thank you so much!

Cheers,
Julien

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (2,184)