Forum Discussion
mbelt
1 year agoRegular Visitor
Median Calculation Fails with Calculation Groups & Field Parameters in Matrix Visual
Reproduction Steps Create a base table with columns for dimension values (e.g., Age Group) and multiple measures (e.g., Alcohol Use, Food Insecurity). Create a calculation group with items referen...
- 1 year ago
Hi mbelt
If dimension is a field parameter, it cannot dynamically reference in a measure. You will need to create a conditoinal measure that switches to different dimensions depending on the selected value in the slicer
MedianPerMeasureX = VAR DimOrder = SELECTEDVALUE('Dimension'[Dimension Order]) -- Summary table for Dimension1 VAR SummaryTable1 = ADDCOLUMNS( ALL('ActualDimTable'[Dimension1]), "@Value", CALCULATE( SELECTEDMEASURE(), REMOVEFILTERS('ActualDimTable'[Dimension1]) ) ) -- Summary table for Dimension2 VAR SummaryTable2 = ADDCOLUMNS( ALL('ActualDimTable'[Dimension2]), "@Value", CALCULATE( SELECTEDMEASURE(), REMOVEFILTERS('ActualDimTable'[Dimension2]) ) ) -- Summary table for Dimension3 VAR SummaryTable3 = ADDCOLUMNS( ALL('ActualDimTable'[Dimension3]), "@Value", CALCULATE( SELECTEDMEASURE(), REMOVEFILTERS('ActualDimTable'[Dimension3]) ) ) -- Conditional return RETURN SWITCH( TRUE(), DimOrder = 1, MEDIANX( FILTER(SummaryTable1, NOT ISBLANK([@Value])), [@Value] ), DimOrder = 2, MEDIANX( FILTER(SummaryTable2, NOT ISBLANK([@Value])), [@Value] ), DimOrder = 3, MEDIANX( FILTER(SummaryTable3, NOT ISBLANK([@Value])), [@Value] ) )
danextian
Super User
1 year agoHi mbelt
If dimension is a field parameter, it cannot dynamically reference in a measure. You will need to create a conditoinal measure that switches to different dimensions depending on the selected value in the slicer
MedianPerMeasureX =
VAR DimOrder = SELECTEDVALUE('Dimension'[Dimension Order])
-- Summary table for Dimension1
VAR SummaryTable1 =
ADDCOLUMNS(
ALL('ActualDimTable'[Dimension1]),
"@Value",
CALCULATE(
SELECTEDMEASURE(),
REMOVEFILTERS('ActualDimTable'[Dimension1])
)
)
-- Summary table for Dimension2
VAR SummaryTable2 =
ADDCOLUMNS(
ALL('ActualDimTable'[Dimension2]),
"@Value",
CALCULATE(
SELECTEDMEASURE(),
REMOVEFILTERS('ActualDimTable'[Dimension2])
)
)
-- Summary table for Dimension3
VAR SummaryTable3 =
ADDCOLUMNS(
ALL('ActualDimTable'[Dimension3]),
"@Value",
CALCULATE(
SELECTEDMEASURE(),
REMOVEFILTERS('ActualDimTable'[Dimension3])
)
)
-- Conditional return
RETURN
SWITCH(
TRUE(),
DimOrder = 1,
MEDIANX(
FILTER(SummaryTable1, NOT ISBLANK([@Value])),
[@Value]
),
DimOrder = 2,
MEDIANX(
FILTER(SummaryTable2, NOT ISBLANK([@Value])),
[@Value]
),
DimOrder = 3,
MEDIANX(
FILTER(SummaryTable3, NOT ISBLANK([@Value])),
[@Value]
)
)