Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a column that may contain zero or multiple values delimited by a semi-colon.
RATING |
5 |
4 |
3;4 |
I would like to average the the ratings in a new custom column. My ideal end-result would be something along the lines of:
RATING | Count of RATING | AVG of Rating |
5 | 1 | 5 |
4 | 1 | 4 |
3;4 | 2 | 3.5 |
Any recommendations?
Solved! Go to Solution.
Hi @dpancratz,
You can follow below steps(Query editor) to achieve your requirement.
Source table:
Add custom column to get the column of subitems.
Count = Table.AddColumn(#"Changed Type", "Count", each if Text.Contains([RATING],";") then List.Count(Text.Split([RATING],";")) else 1)
Add custom column to get the average of subitems.
Average = Table.AddColumn(Count, "Average", each if Text.Contains([RATING],";") then List.Average(List.Transform(Text.Split([RATING],";"), each Number.FromText(_))) else Number.FromText([RATING]))
Test more records:
Full Query:
let Source = Excel.Workbook(File.Contents("C:\Users\xxxxx\Desktop\test.xlsx"), null, true), Sheet8_Sheet = Source{[Item="Sheet8",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet8_Sheet), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"RATING", type text}}), Count = Table.AddColumn(#"Changed Type", "Count", each if Text.Contains([RATING],";") then List.Count(Text.Split([RATING],";")) else 1), Average = Table.AddColumn(Count, "Average", each if Text.Contains([RATING],";") then List.Average(List.Transform(Text.Split([RATING],";"), each Number.FromText(_))) else Number.FromText([RATING])) in Average
Comments.
Text.Split : split the text by ";".
List.Transform : transform a text list to number list.(the prerequisite steps)
List.Average : get the average of the list. (only work on numeric list)
Regards,
Xiaoxin Sheng
Hi @dpancratz,
You can follow below steps(Query editor) to achieve your requirement.
Source table:
Add custom column to get the column of subitems.
Count = Table.AddColumn(#"Changed Type", "Count", each if Text.Contains([RATING],";") then List.Count(Text.Split([RATING],";")) else 1)
Add custom column to get the average of subitems.
Average = Table.AddColumn(Count, "Average", each if Text.Contains([RATING],";") then List.Average(List.Transform(Text.Split([RATING],";"), each Number.FromText(_))) else Number.FromText([RATING]))
Test more records:
Full Query:
let Source = Excel.Workbook(File.Contents("C:\Users\xxxxx\Desktop\test.xlsx"), null, true), Sheet8_Sheet = Source{[Item="Sheet8",Kind="Sheet"]}[Data], #"Promoted Headers" = Table.PromoteHeaders(Sheet8_Sheet), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"RATING", type text}}), Count = Table.AddColumn(#"Changed Type", "Count", each if Text.Contains([RATING],";") then List.Count(Text.Split([RATING],";")) else 1), Average = Table.AddColumn(Count, "Average", each if Text.Contains([RATING],";") then List.Average(List.Transform(Text.Split([RATING],";"), each Number.FromText(_))) else Number.FromText([RATING])) in Average
Comments.
Text.Split : split the text by ";".
List.Transform : transform a text list to number list.(the prerequisite steps)
List.Average : get the average of the list. (only work on numeric list)
Regards,
Xiaoxin Sheng
After you've split the Column in the Query Editor - select the unique row identifier column (or index column)
still in the Query Editor - Transform Tab - click Unpivot Other Columns - then Home tab - Close and Apply
Then create 2 Measures
Ratings Measure = COUNTROWS ( Table ) and
Avg Rating Measure = DIVIDE ( SUM (Table[Value] ), [Ratings Measure], 0 )
Then here's the Table Visual
Here's what I've tried so far:
1. Split the column [RATING] be deliminator
2. Creating a custom column and trying to figure out the DAX function to get what i want
I'm somewhat new, so I'm quickly runningout of ideas.
It's not very pretty (so you might keep hunting) but this worked for me:
The end result looks like this:
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
82 | |
70 | |
60 |
User | Count |
---|---|
149 | |
114 | |
107 | |
89 | |
67 |