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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ben_E_556
Frequent Visitor

Creating an unpivoted table of measures

Hello,

 

I have multiple tables connected via relationships. In my simplified example, there are three tables with utility data that are connected by utility name. Some of these tables have multiple years of data per utility, some do not.

 

I am looking to unpivot a table with one row per utility where some columns are measures that summarize multiple years of data. I'm able to create a table with one row per utility with multiple summarization measures in my data view, but I cannot unpivot this table of measures to create a long table with 3 columns (utility, measure, value). 

 

For context, I'm looking to create a correlation grid where I compare multiple metrics together. I'm looking to be able to compare average values by utilility with overall scores by utility. 

 

In order to create the correlation grid, we need a data frame where all values are in one column. I've tried various ways, but I'm getting stuck trying to create a correlation matrix between the summarized measures.

 

Pasting example data below and the correlation formula with screenshots.

 

This screenshot shows my correlation matrix for one of the tables. I'm unable to get summarization measures from other tables in the matrix. I would like "average percent_adv" and "average outage length" and "average outage min" in the below matrix.

ben_E_556_0-1697317328026.png

ben_E_556_1-1697317328014.png

 

 

utilityYearpercent_adv
F20210.01011538
I20210.9483634
G20210.61273015
D20211
C20210.73086045
A20210.94885022
J20211
B20210.97884053
H20211
E20211
F20200.00016183
I20200.74107892
G20200.55757024
D20201
C20200.67148985
A20200.95288265
J20201
B20200.98621083
H20201
E20201
F20190.00012355
I20190.59810882
G20190.57252318
D20190.99995823
C20190.35195303
A20190.92042736
J20191
B20190.86401994
H20191
E20191
F20180.00012698
I20180.47154228
G20180.57484172
D20180.99288994
C20180.0455672
A20180.84680691
J20181
B20180.53876631
H20181
E20181
F20170.00010812
I20170.27741826
G20170.54328045
D20170.9568745
C20170.00325753
A20170.75493245
J20171
B20170.21102577
H20171
E20171

 

utilityYearoutage_minoutage_length
A2021111.21.311
B202165.3790.88
C2021200.42.57
D2021264.133.1
E202150.080.81
F202157.890.84
G20211640
H20215.11 
I20213.9972.866
J202141.9940.844
A2020108.2111.363
B202090.60.821
C2020225.1922.842
E202036.260.66
F202059.320.868
G2020237 
H2020351.42 
I2020206.42.45
J202031.8270.52
A2019125.821.47
B201985.5360.774
C2019280.1333.23
E201951.370.5
F201915.8950.486
G2019265.2 
H2019444.84 
I2019270.62.88
J201952.7070.974
A2018153.82.06
B2018  
C2018294.9423.338
E201840.0550.5
F201814.5870.4
G2018138.6 
H2018289.08 
I2018230.362.607
J201837.2660.84
A2017131.861.87
B2017  
C2017220.0611.995
E201732.305 
F201712.4410.003
G2017299.4 
H2017216.06 
I2017381.721.479
J201728.6190.585

 

utilitycustomer_scoreemployee_score
A135111
B161133
C11081
D147114
E14581
F10739
G16275
H14885
I14186
J12880
Correlation Coeff =
 DIVIDE(
     [n_utility]*[XY] - [X]*[Y],
     SQRT(
         ([n_utility]*[X^2] - [X]^2) * ([n_utility]*[Y^2]-[Y]^2)
     )
 )
 
Y^2 =
 VAR CurrentX = SELECTEDVALUE('Attributes (2)'[Attribute])
 VAR CurrentY = SELECTEDVALUE(Attributes[Attribute])
 VAR Virtual =
 SUMMARIZE(
     'Score Pivot',
     'Score Pivot'[utility],
     "X",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentX),
     "Y",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentY)
 )
RETURN
SUMX(
    Virtual,
    [Y] * [Y]
)
 
Y =
 VAR CurrentX = SELECTEDVALUE('Attributes (2)'[Attribute])
 VAR CurrentY = SELECTEDVALUE(Attributes[Attribute])
 VAR Virtual =
 SUMMARIZE(
     'Score Pivot',
     'Score Pivot'[utility],
     "X",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentX),
     "Y",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentY)
 )
RETURN
SUMX(
    Virtual,
    [Y]
)
 
XY =
 VAR CurrentX = SELECTEDVALUE('Attributes (2)'[Attribute])
 VAR CurrentY = SELECTEDVALUE(Attributes[Attribute])
 VAR Virtual =
 SUMMARIZE(
     'Score Pivot',
     'Score Pivot'[utility],
     "X",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentX),
     "Y",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentY)
 )
RETURN
SUMX(
    Virtual,
    [X] * [Y]
)
X^2 =
 VAR CurrentX = SELECTEDVALUE('Attributes (2)'[Attribute])
 VAR CurrentY = SELECTEDVALUE(Attributes[Attribute])
 VAR Virtual =
 SUMMARIZE(
     'Score Pivot',
     'Score Pivot'[utility],
     "X",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentX),
     "Y",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentY)
 )
RETURN
SUMX(
    Virtual,
    [X] * [X]
)
 
X =
 VAR CurrentX = SELECTEDVALUE('Attributes (2)'[Attribute])
 VAR CurrentY = SELECTEDVALUE(Attributes[Attribute])
 VAR Virtual =
 SUMMARIZE(
     'Score Pivot',
     'Score Pivot'[utility],
     "X",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentX),
     "Y",CALCULATE(MAX('Score Pivot'[Value]), 'Score Pivot'[Attribute] = CurrentY)
 )
RETURN
SUMX(
    Virtual,
    [X]
)
1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @ben_E_556,

Current power bi does not support create dynamic calculated column/table based on filter effects. They do not work on the same data level, and you can't use child level to affect its parent.

Measure expressions are calculated based on row and filter context, use them in table/column will fix the calculation result and not able to respond with filter effects.

In my opinion, I'd like to suggest only create the table with specific category and measure names, then you can write formula with switch function to check current category values to look up and redirect to different calculation results.

Notice: the data level of power bi(from parent to child level)

Database(external) -> query table(query, custom function, query parameters) -> data model table(table, calculate column/table) -> data view with virtual tables(measure, visual, filter, slicer)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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