Forum Discussion
NewToPowerBI2
2 years agoNew Member
Creating a correlation matrix for two multi-value variables?
Hello, I need some guidance on creating a correlation matrix between two multi-value variables. Sample data: 1. Desired end-result (this was manually counted, incomplete and might have er...
lbendlin
2 years agoSuper User
You're on the right track, sort of. First step is to create all permutations between x and y values. The index column is interesting but not really needed (except maybe for the self correlation you mentioned).
So you go from
to
by using two simple splits
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("NU7LFcAwCNrFM4dG82lnycv+azQQc9AnCOicVgxWELs7AtUWpjnRrsCAiwmhLlUXU+lTEbU9kalouae2wdVP6mBG3jmu9zjkJf5ScfflyUcUun4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, #"Variable X" = _t, #"Variable Y" = _t]),
#"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Variable X", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Variable X"),
#"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Split Column by Delimiter", {{"Variable Y", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Variable Y"),
#"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Index", Int64.Type}, {"Variable X", Int64.Type}, {"Variable Y", Int64.Type}})
in
#"Changed Type"
Then in DAX you can do a simple Pearson correlation from a quick measure if you like.
, you can modify the auto generated code, or you can roll your own.