cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Combining two values of collection into one value

I'm Having a Collection as Shown Here:CollectionCollection

 

Now i've to combine both the Sharepoint;nintex and nintex;sharepoint into one value i.e sharepoint;nintex and remove the nintex;sharepoint from the final collection

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Combining two values of collection into one value

@Krishna98 
This was a fun little challenge to do.  Good news!  It will work on any pairing of values: not just the ones you submitted.

 

//Original collection
ClearCollect(
    myCollection,
    ["SharePoint;Nintex", "Nintex;SharePoint", "SharePoint;Power Platform"]
);

// Solution collection with only unique pairs
ClearCollect(
    mySolution,
    RenameColumns(
        Distinct(
            AddColumns(
                myCollection,
                "SortedValues", Concat(Sort(Split(Value, ";"), Result, Ascending),Result & ";")
            ), 
            SortedValues
        ),
        "Result", "Value"
    )
)

 

---
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

4 REPLIES 4
Highlighted
Super User
Super User

Re: Combining two values of collection into one value

@Krishna98 
This was a fun little challenge to do.  Good news!  It will work on any pairing of values: not just the ones you submitted.

 

//Original collection
ClearCollect(
    myCollection,
    ["SharePoint;Nintex", "Nintex;SharePoint", "SharePoint;Power Platform"]
);

// Solution collection with only unique pairs
ClearCollect(
    mySolution,
    RenameColumns(
        Distinct(
            AddColumns(
                myCollection,
                "SortedValues", Concat(Sort(Split(Value, ";"), Result, Ascending),Result & ";")
            ), 
            SortedValues
        ),
        "Result", "Value"
    )
)

 

---
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

Highlighted
Frequent Visitor

Re: Combining two values of collection into one value

Thnq So Much @mdevaney 

it's working super fine.

 

may i know the explanation of how this formula working ?

Highlighted
Super User
Super User

Re: Combining two values of collection into one value

@Krishna98 

Yes of course Krishna!  This is the one line of code that you must understand how-it-works in order to understand the rest

Concat(Sort(Split(Value, ";"), Result, Ascending),Result & ";")

 

What does it do?  It attacks the main problem: you want to remove the duplicates but the pairing could be in any-order.  We need the order to be alphabetical (A-to-Z) instead.

"Nintex; SharePoint"
"SharePoint; Nintex"
"SharePoint; Power Platform"

 

This code breaks the text-strings into tables.

Code:
Split(Value, ";")

Output:
{Result: ["Nintex", "SharePoint"]}, {Result: ["SharePoint", "Nintex"]}, {Result: ["SharePoint", "Power Platform"]} 

 

 

Then we sort the tables.

Code:
Sort(Split(Value, ";"), Result, Ascending)

Output:
{Result: ["Nintex", "SharePoint"]}, {Result: ["Nintex", "SharePoint"]}, {Result: ["Nintex", "Power Platform"]} 

 

And change them back into a text-string

Code:
Concat(Sort(Split(Value, ";"), Result, Ascending),Result & ";")

Output:
{Result: ["Nintex", "SharePoint"]}, {Result: ["Nintex", "SharePoint"], {Result: ["Nintex", "Power Platform"]} 

 

Now we can remove the duplicates because we know the order will be the same.

Code:
Distinct(
    AddColumns(
        myCollection,
        "SortedValues", Concat(Sort(Split(Value, ";"), Result, Ascending),Result & ";")
    ), 
    SortedValues
)

Output:
{Result: ["Nintex", "SharePoint"]}, {Result: ["Nintex", "Power Platform"]} 

 

 

---
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."

Highlighted
Frequent Visitor

Re: Combining two values of collection into one value

Thank You So Much 🙂 🙂  @mdevaney 

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (4,190)