Forum Discussion
shugs
9 years agoRegular Visitor
Multiple choices answer count
Hi, I'm new to Power BI and I can't figure out how to count the number of occurence of each answer from a multiple choice sharepoint form : I have : Project ¦ Choice ...
- 9 years ago
Hi shugs,
If you data is in that format you present first of all you need to change you information format.
Go to the query editor and do the following steps:
- Choose column Choice
- Transform -> Split column -> By Delimeter
- Choose the comma as your delimeter
- Now you have a table with Project and one column per response
- Choose all the columns besides the project
- Transform -> Unpivot Columns
- Return a table with: Project, Attribute, Value
- Delete column Attribute
- Rename Value to your choice
- Save and return to PBI desktop
Now just add you Value to the table visual and the Project (this should be count)
Regards,
MFelix
MarcelBeug
9 years agoCommunity Champion
Alternative solution in Power Query:
- Remove empty Choices
- Choose tab Transform - Format - Trim
Adjust the generated code to use Text.Split (on ","), which will result in nested lists - Remove Project column
- Expand the "Choice" column
- Choose tab Transform - Group By Choice and count rows (which is the default operation)
In the popup screen of "Group By", name the new column "Number of occurrence".
Resulting code (in which I adjusted the step names for better readability):
let
Source = InputTable,
RemovedEmpties = Table.SelectRows(Source, each ([Choice] <> null)),
Splitted = Table.TransformColumns(RemovedEmpties,{{"Choice", each Text.Split(_, ",")}}),
RemovedProject = Table.RemoveColumns(Splitted,{"Project"}),
ExpandedChoice = Table.ExpandListColumn(RemovedProject, "Choice"),
Trimmed = Table.TransformColumns(ExpandedChoice,{},Text.Trim),
GroupedWithCount = Table.Group(Trimmed, {"Choice"}, {{"Number of occurrence", each Table.RowCount(_), type number}})
in
GroupedWithCount