cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gmbeee
Helper II
Helper II

Chart multi choice columns

Hi,

 

Im trying to display a chart based around a multi choice column in a SP list.


It works, however displays multi selections as new items.

 

for example:

 

if I have an item which has a multi select field containing:

 

ITEM      |     CHOICE

 

1            |      Choice1

2            |      Choice2

3            |      Choice1,Choice2

 

The Chart has a bars for:

 

“Choice1” - Count = 1

“Choice2” - Count = 1

”Choice1,Choice2” - Count = 1

 

How can I get:

 

“Choice1” - Count = 2

“Choice2” - Count = 2

 

Heres the formula I’m using:

 

AddColumns(

    GroupBy(

        AddColumns(

            Filter(

                colTIR,

                (Created >= DateStart.SelectedDate) && (Created <= DateEnd.SelectedDate)

            ),

            "TIR_Field",

            Switch(

                Dropdown1.Selected.Value,

                "Data by TEAM",

                TEAM.Value,

                "Data by STATUS",

                Concat(

                    STATUS,

                    Value,

                    ","

                ),

                "Data by FLAG",

                Concat(

                    FLAGS,

                    Value,

                    ","

                )

            )

        ),

        "TIR_Field",

        "byTIR_FILTER"

    ),

    "Count",

    CountRows(byTIR_FILTER)

)

 

The source is filtered by a date picker and a dropdown.


Thanks. I’m going round in circles…

1 ACCEPTED SOLUTION

Accepted Solutions

@gmbeee 

There are probably a few ways to do this but I managed it using a With statement to capture the different choice columns. I added another Choice column to myList called TextChoice then added this to a DropDown

 

Items: ["NumberChoice", "TextChoice"]

OnChange:

With(
    {
        wChoice1: Concat(myList.NumberChoice,
                    Concat(NumberChoice.Value, Value & ",")
                    & ","),
        
        wChoice2: Concat(myList.TextChoice,
                    Concat(TextChoice.Value, Value & ",")
                    & ",")
    },

    // get Choices into a Single string seperated by commas
    Switch(Dropdown1.Selected.Value,
        "NumberChoice", ClearCollect(colChoices, wChoice1),
        "TextChoice", ClearCollect(colChoices, wChoice2)
    );

    // Split the above string on comma
    ClearCollect(
        colSplit,
        Split(
            First(colChoices).Value,
            ","
        )
    );
    // Remove blanks created in the Split table by extra commas
    RemoveIf( colSplit, Result = "");

    // create collection of Distinct Choices and their Counts
    ClearCollect(
        colDistinct,
        AddColumns(
            RenameColumns(
                Distinct(colSplit,Result),
                "Result",
                "Choice"
            ),
            "Count",
            CountRows(
                Filter( colSplit, Result = Choice )
            )
        )
    )
)

 

Hope that makes sense.

View solution in original post

5 REPLIES 5
EddieE
Super User
Super User

@gmbeee 

This code is pretty hacky but seems to do what you want.

 

I have a SharePoint List with a Multi Choice column of Numbers called 'NumberChoice'. This code works on that column

 

// get Choices into a Single string seperated by commas
ClearCollect(
    colChoices,
    Concat(
        myList.NumberChoice,
        Concat(
            NumberChoice.Value, Value & ",")
        & ","
    )
);
// Split the above string on comma
ClearCollect(
    colSplit,
    Split(
        First(colChoices).Value,
        ","
    )
);
// Remove blanks created in the Split table by extra commas
RemoveIf( colSplit, Result = "");

// create collection of Distinct Choices and their Counts
ClearCollect(
    colDistinct,
    AddColumns(
        RenameColumns(
            Distinct(colSplit,Result),
            "Result",
            "Choice"
        ),
        "Count",
        CountRows(
            Filter( colSplit, Result = Choice )
        )
    )
)

 

Output:

CountChoice_values.jpg

What the SP List data looks like:

CountChoice_data.jpg

 

 

This is brilliant. It works perfectly.

 

As you say, the code isn’t great. What’s the best way to update the collection colDistinct based on a drop down between 3 different multi select columns.

 

I want to dynamically change the chart between fields, based on the drop down selection.

@gmbeee 

There are probably a few ways to do this but I managed it using a With statement to capture the different choice columns. I added another Choice column to myList called TextChoice then added this to a DropDown

 

Items: ["NumberChoice", "TextChoice"]

OnChange:

With(
    {
        wChoice1: Concat(myList.NumberChoice,
                    Concat(NumberChoice.Value, Value & ",")
                    & ","),
        
        wChoice2: Concat(myList.TextChoice,
                    Concat(TextChoice.Value, Value & ",")
                    & ",")
    },

    // get Choices into a Single string seperated by commas
    Switch(Dropdown1.Selected.Value,
        "NumberChoice", ClearCollect(colChoices, wChoice1),
        "TextChoice", ClearCollect(colChoices, wChoice2)
    );

    // Split the above string on comma
    ClearCollect(
        colSplit,
        Split(
            First(colChoices).Value,
            ","
        )
    );
    // Remove blanks created in the Split table by extra commas
    RemoveIf( colSplit, Result = "");

    // create collection of Distinct Choices and their Counts
    ClearCollect(
        colDistinct,
        AddColumns(
            RenameColumns(
                Distinct(colSplit,Result),
                "Result",
                "Choice"
            ),
            "Count",
            CountRows(
                Filter( colSplit, Result = Choice )
            )
        )
    )
)

 

Hope that makes sense.

Thanks @EddieE 

 

This makes perfect sense. I’ve combined it with a non choice column and it’s working great. 👍

@gmbeee 

Great to see you got it working mate ... and even extended it! Nice one 🙂  

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

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