Forum Discussion
Matrix sub-total calculation?
- 5 years ago
Final PBIX File here: https://drive.google.com/file/d/12_k_tO8BdrXV73Lbho_whabGP-jOlasP/view?usp=sharing
Code to create the weighted average measure:
WAVG Measure = VAR DESIRED_ROWS = FILTER( 'Table', 'Table'[Column1] > 0 && 'Table'[Attribute (from a PowerQuery unpivot] = "attribute1 selected" || 'Table'[Attribute (from a PowerQuery unpivot] = "attribute2 selected" || 'Table'[Attribute (from a PowerQuery unpivot] = "attribute3 selected" || ) RETURN DIVIDE( SUMX ( DESIRED_ROWS, 'Table'[Denominator Column] * 'Table'[Value] ), SUMX ( DESIRED_ROWS, 'Table'[Denominator Column] ) )Code to generate Matrix values from a weighted average measure:
_A = // Note - below one can use any of the *X DAX functions, such as SUMX, AVERAGEX, MEDIANX, STDEVX.S, etc. VAR OUTPUT = AVERAGEX( SUMMARIZE ( ALLSELECTED('Table'), 'Table'[Row Column] ) , [WAVG Measure] ) RETURN OUTPUTCode to summarize the Matrix value [measure]
_A Summarized = // Choose AVERAGEX or SUMX below depending on one's needs VAR OUTPUT_CELL = AVERAGEX( SUMMARIZE('Table','Table'[Matrix Row Column]) , [WAVG measure] ) RETURN OUTPUT_CELL
Premature, but making progress.
The new interim step measure, {A int1} goes onto the matrix in individual cells as [Units] * [{A}] and is calculating correctly at an individual cell level. The [Units] is calculating correctly at both individual and row-subtotal level.
So now trying to summarize {A int1}, consistently associated with the individual cell data that is going into it.
Final PBIX File here: https://drive.google.com/file/d/12_k_tO8BdrXV73Lbho_whabGP-jOlasP/view?usp=sharing
Code to create the weighted average measure:
WAVG Measure =
VAR DESIRED_ROWS =
FILTER(
'Table',
'Table'[Column1] > 0 &&
'Table'[Attribute (from a PowerQuery unpivot] = "attribute1 selected" ||
'Table'[Attribute (from a PowerQuery unpivot] = "attribute2 selected" ||
'Table'[Attribute (from a PowerQuery unpivot] = "attribute3 selected" ||
)
RETURN
DIVIDE(
SUMX (
DESIRED_ROWS,
'Table'[Denominator Column] * 'Table'[Value]
),
SUMX (
DESIRED_ROWS,
'Table'[Denominator Column]
)
)
Code to generate Matrix values from a weighted average measure:
_A =
// Note - below one can use any of the *X DAX functions, such as SUMX, AVERAGEX, MEDIANX, STDEVX.S, etc.
VAR OUTPUT =
AVERAGEX(
SUMMARIZE (
ALLSELECTED('Table'),
'Table'[Row Column]
)
, [WAVG Measure]
)
RETURN
OUTPUT
Code to summarize the Matrix value [measure]
_A Summarized =
// Choose AVERAGEX or SUMX below depending on one's needs
VAR OUTPUT_CELL =
AVERAGEX(
SUMMARIZE('Table','Table'[Matrix Row Column])
, [WAVG measure]
)
RETURN
OUTPUT_CELL