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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
mbelt
Regular Visitor

Median Calculation Fails with Calculation Groups & Field Parameters in Matrix Visual

Reproduction Steps

  1. Create a base table with columns for dimension values (e.g., Age Group) and multiple measures (e.g., Alcohol Use, Food Insecurity).
  2. Create a calculation group with items referencing each base measure.
  3. Create a field parameter to switch between dimensions.
  4. Build a matrix visual:
    • Rows: Calculation group
    • Columns: Field parameter dimension values
    • Values: SELECTEDMEASURE()
  5. Add a measure to calculate the median across all dimension values:

MedianPerMeasureX =
VAR SummaryTable =
ADDCOLUMNS(
ALL('Dimension'[Dimension]),
"@Value",
CALCULATE(
SELECTEDMEASURE(),
REMOVEFILTERS('Dimension'[Dimension])
)
)
RETURN
MEDIANX(
FILTER(SummaryTable, NOT ISBLANK([@Value])),
[@Value]
)

 

Expected Behavior
The median measure should return a constant value per row (i.e., per measure), representing the median of all dimension values.

Actual Behavior
The median measure returns the same value as the original measure, not the median across dimension values.

 

Environment

  • Power BI Desktop Version: 2.145.1602.0 64-bit (July 2025)
  • Calculation groups created via modeling UI
  • Field parameters created via modeling UI
1 ACCEPTED SOLUTION
danextian
Super User
Super User

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]
            )
    )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

5 REPLIES 5
v-kpoloju-msft
Community Support
Community Support

Hi @mbelt,
Thank you for reaching out to the Microsoft fabric community forum. 

Has your issue been resolved? If the response provided by the community member @danextian, @OwenAuger, addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

Thank you for using the Microsoft Community Forum.

Hi @mbelt,

Just checking in to see if the issue has been resolved on your end. If the earlier suggestions helped, that’s great to hear! And if you’re still facing challenges, feel free to share more details happy to assist further.

Thank you.

Hi @mbelt,

Hope you had a chance to try out the solution shared earlier. Let us know if anything needs further clarification or if there's an update from your side always here to help.

Thank you.

danextian
Super User
Super User

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]
            )
    )

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
OwenAuger
Super User
Super User

Hi @mbelt 

 

I'm assuming the 'Dimension' table is a field parameter table set up via the Power BI Desktop interface. Is that right?

If so, one issue within your MedianPerMeasureX measure is that a field parameter column, such as 'Dimension'[Dimension], does not function as a dynamic column reference.

So the expression

ALL ( 'Dimension'[Dimension] )

does not dynamically produce a single-column table containing all values of the column selected via the field parameter, but produces a single-column table containing all values in the 'Dimension'[Dimension] column itself. So it does not have the intended effect when used in an iterator.

 

To help come up with a solution, could you share a simple PBIX set up as you have described, along with the expected measure values as an example?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.