Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Sunbeam21
New Member

Creating a total score for values in a concatenated and comma separated list

 

My data source is in Excel and it contains responses to a list of questions, many of which involve selecting multiple values from a list of values.  In the Excel output, these multiple responses are recorded in a single cell as a concatenated, comma separated list.  Each value has a weighted score and I need to calculate the total score for all the selected responses, ideally by looking up the score from a table.  See example below:

 

Desired result = Total score column shown in first table.  The lookup table for the scores for each 'fruit value' is set out below that.  Is there any way to do this in a fairly easy way?

 

FruitTotal score
Apple, Lemon, Pear, Orange21
Lemon, Pear6
Apple10
Orange5

 

Lookup tableScore
Apple10
Lemon4
Pear2
Orange5
1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Yes: In your first table ("Combinations"), you add a column that splits the text-string with the combinations into a list:

Text.Split([Combinations], ",")

 

Then you expand that column. This will produce a row per fruit.

Next step is to clean that text befor merging it with the LookupTable.

You then expand the lookup value.

Last step you group on the combination-field and aggregate those values with a sum.

 

This is the full code:

let
    Source = Combinations,
    #"Added Custom" = Table.AddColumn(Source, "List", each Text.Split([Combinations], ",")),
    #"Expanded List" = Table.ExpandListColumn(#"Added Custom", "List"),
    #"Trimmed Text" = Table.TransformColumns(#"Expanded List",{{"List", Text.Trim}}),
    #"Merged Queries" = Table.NestedJoin(#"Trimmed Text",{"List"},LookupTable,{"Fruit"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Score"}, {"Score"}),
    #"Grouped Rows" = Table.Group(#"Expanded NewColumn", {"Combinations"}, {{"Total Score", each List.Sum([Score]), type number}})
in
    #"Grouped Rows"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Community Champion
Community Champion

Yes: In your first table ("Combinations"), you add a column that splits the text-string with the combinations into a list:

Text.Split([Combinations], ",")

 

Then you expand that column. This will produce a row per fruit.

Next step is to clean that text befor merging it with the LookupTable.

You then expand the lookup value.

Last step you group on the combination-field and aggregate those values with a sum.

 

This is the full code:

let
    Source = Combinations,
    #"Added Custom" = Table.AddColumn(Source, "List", each Text.Split([Combinations], ",")),
    #"Expanded List" = Table.ExpandListColumn(#"Added Custom", "List"),
    #"Trimmed Text" = Table.TransformColumns(#"Expanded List",{{"List", Text.Trim}}),
    #"Merged Queries" = Table.NestedJoin(#"Trimmed Text",{"List"},LookupTable,{"Fruit"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Score"}, {"Score"}),
    #"Grouped Rows" = Table.Group(#"Expanded NewColumn", {"Combinations"}, {{"Total Score", each List.Sum([Score]), type number}})
in
    #"Grouped Rows"

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.