cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DaftNewb
Helper I
Helper I

Combining strings from labels with comma

Hello everyone,

i was doing a few formulas on powerapps that i'm trying to combine, for text purposes i've made one for each ComboBox(that goes from 1 to 10).

I want to unite them using a comma for example (string1),(string2) and like the example the expected result is to have commas only in between the content.

I was trying to use Concatenate but if for example they are out of order the result can look like this :

,(string3),(string5),(string7), or ,(string6),

wich is not what i expect as result.

 

Is there a better way of doing this? i'm quite new at powerapps and this problem looks like it must have a pretty obvious solution but i don't know how to make it.

Thanks in advance for every help given.

1 ACCEPTED SOLUTION

Accepted Solutions

There are a few ways to get the result you desire, a quick and basic one is to use IsBlank

one way to do it is: Concatenate(If(!IsBlank(ComboBox1.Selected.Value1),","&ComboBox1.Selected.Value1),If(!IsBlank(Dropdown1.Selected.Value),","&Dropdown1.Selected.Value))

what this is saying is concatenate all of this where it is not blank and add a comma before it. you realistically do not need to use concatenate you could just use & and combine the ifs together with that but either is fine. So to add another to concatenate is just as simple as adding another , and if like this:

 

Concatenate(If(!IsBlank(ComboBox1.Selected.Value1),","&ComboBox1.Selected.Value1),If(!IsBlank(Dropdown1_1.Selected.Value),","&Dropdown1_1.Selected.Value),If(!IsBlank(Dropdown1.Selected.Value),","&Dropdown1.Selected.Value))

 

So the below gets rid of the commas that have no values as mentioned.

Concatenate(
    If(
        !IsBlank(ComboBox1.Selected.Value1),
        "," & ComboBox1.Selected.Value1
    ),
    If(
        !IsBlank(Dropdown1.Selected.Value),
        "," & Dropdown1.Selected.Value
    )
)

 

but it may give you a comma at the beginning which you do not want. If that happens it is a very quick fix

 

Using Find and Mid

 

you would just do :

With(
    {
        varConcatenatedText: Concatenate(
            If(
                !IsBlank(ComboBox1.Selected.Value1),
                "," & ComboBox1.Selected.Value1
            ),
            If(
                !IsBlank(Dropdown1.Selected.Value),
                "," & Dropdown1.Selected.Value
            )
        )
    },
    If(
        Find(
            ",",
            varConcatenatedText
        ) = 1,
        Mid(
            varConcatenatedText,
            2
        ),
        varConcatenatedText
    )
)

 

i tested it in my apps and it worked let me know if you have questions Personally I recommend the last option to get the most desired result.



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

View solution in original post

5 REPLIES 5
DaftNewb
Helper I
Helper I

.

v-liwei-msft
Microsoft
Microsoft

Hi @DaftNewb ,

 

Could you please tell me if you want to combine the selection results of these ten combobox into a string?

 

You can use the concatenate function to concatenate these results and add commas directly in the middle of the results:

Concatenate(Dropdown1.Selected.Value,",",Dropdown1_1.Selected.Value,",",Dropdown1_2.Selected.Value)

 

 I have made a test for your reference:

vliweimsft_0-1653646598739.png

 

Best Regards,

Levi

when i don't select nothing using concatenate the comma maintains there atm i have  6 of them displaying on the screen: ",,,,,,"

and since i have 6 other dropdown items the commas also stay in place if i select only something on the second one like : ,string2,,,,,,

Mike2500
Super User
Super User

I didn't understand your comment about the possibility of things being out of order, but yes, this is pretty tricky due to not knowing which items might have a value. But the following works:

 

With(
    {
        str: Concatenate(
            If(IsBlank(Dropdown1.Selected.Value),"", Dropdown1.Selected.Value & ", "),
            If(IsBlank(Dropdown2.Selected.Value),"", Dropdown2.Selected.Value & ", "),
            If(IsBlank(Dropdown3.Selected.Value),"", Dropdown3.Selected.Value & ", ")
        )
    },
    Left(
        str,
        Len(str) - 2
    )
)

Reading this starting from the inside:

Each if statement returns either an empty string or the dropdown concatenated with a comma and space. All of these are then concatenated together. (if a dropdown is empty, then nothing is added to the string as the result of the IF is an empty string for that dropdown). The result of the concatenate is stored in a local variable named "str". The left function then removes the last two characters of str (the last comma and space) and returns the result.

There are a few ways to get the result you desire, a quick and basic one is to use IsBlank

one way to do it is: Concatenate(If(!IsBlank(ComboBox1.Selected.Value1),","&ComboBox1.Selected.Value1),If(!IsBlank(Dropdown1.Selected.Value),","&Dropdown1.Selected.Value))

what this is saying is concatenate all of this where it is not blank and add a comma before it. you realistically do not need to use concatenate you could just use & and combine the ifs together with that but either is fine. So to add another to concatenate is just as simple as adding another , and if like this:

 

Concatenate(If(!IsBlank(ComboBox1.Selected.Value1),","&ComboBox1.Selected.Value1),If(!IsBlank(Dropdown1_1.Selected.Value),","&Dropdown1_1.Selected.Value),If(!IsBlank(Dropdown1.Selected.Value),","&Dropdown1.Selected.Value))

 

So the below gets rid of the commas that have no values as mentioned.

Concatenate(
    If(
        !IsBlank(ComboBox1.Selected.Value1),
        "," & ComboBox1.Selected.Value1
    ),
    If(
        !IsBlank(Dropdown1.Selected.Value),
        "," & Dropdown1.Selected.Value
    )
)

 

but it may give you a comma at the beginning which you do not want. If that happens it is a very quick fix

 

Using Find and Mid

 

you would just do :

With(
    {
        varConcatenatedText: Concatenate(
            If(
                !IsBlank(ComboBox1.Selected.Value1),
                "," & ComboBox1.Selected.Value1
            ),
            If(
                !IsBlank(Dropdown1.Selected.Value),
                "," & Dropdown1.Selected.Value
            )
        )
    },
    If(
        Find(
            ",",
            varConcatenatedText
        ) = 1,
        Mid(
            varConcatenatedText,
            2
        ),
        varConcatenatedText
    )
)

 

i tested it in my apps and it worked let me know if you have questions Personally I recommend the last option to get the most desired result.



Signature:


If you appreciated my comments/responses please be sure to Like/Kudo them it really does make me smile 🙂 !
Link to the Power Platform Professionals United Kingdom User Group:

https://powerusers.microsoft.com/t5/Power-Platform-Professionals/gh-p/PowerPlatformProfessionalsUnit...

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Government Carousel

New forum: GCC, GCCH, DoD - Federal App Makers (FAM)

In response to the unique and evolving requirements of the United States public sector, Microsoft has created Power Apps US Government.

Users online (3,342)