Forum Discussion
dylanrollins
3 years agoRegular Visitor
Sliceable Chart Featuring Multiple Table Columns
Hi, I have a data table based on responses to an MS Form, with several yes/no questions being split out over separate columns. I.e.: Key Company Department Question1 Question2 Question3 ...
DataInsights
3 years agoSuper User
A simpler solution is to unpivot the Question columns in Power Query. Here's the M code. I added the step ReplaceEmptyWithNull to replace empty strings with null (your model may not require this step, depending on your data).
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText(
"i45WMlTSUUrOzy1IzKsEMVNSCxKLSnJT80pAPL98IBGZWgxhxupEKxkhlBuhKDeCq4QyQKqNcak2hhkOtwGk3ASXW4wgxoIQSJ0pLmMN4Y5AkLGxAA==",
BinaryEncoding.Base64
),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [
Key = _t,
Company = _t,
Department = _t,
Question1 = _t,
Question2 = _t,
Question3 = _t
]
),
ChangeType = Table.TransformColumnTypes(
Source,
{
{"Key", Int64.Type},
{"Company", type text},
{"Department", type text},
{"Question1", type text},
{"Question2", type text},
{"Question3", type text}
}
),
UnpivotColumns = Table.UnpivotOtherColumns(
ChangeType,
{"Key", "Company", "Department"},
"Attribute",
"Value"
),
RenameColumn = Table.RenameColumns(UnpivotColumns, {{"Attribute", "Question"}}),
ReplaceEmptyWithNull = Table.ReplaceValue(
RenameColumn,
"",
null,
Replacer.ReplaceValue,
{"Value"}
)
in
ReplaceEmptyWithNull
Create measure:
Yes Answers =
VAR vNumerator =
CALCULATE ( COUNT ( Table1[Value] ), Table1[Value] = "Yes" )
VAR vDenominator =
COUNT ( Table1[Value] )
VAR vResult =
DIVIDE ( vNumerator, vDenominator )
RETURN
vResult
---