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
Connor888
Frequent Visitor

Calculate average of a measure over multiple tables, with a field parameter

This is a little like a recent question I asked here. I am using a field parameter to produce (among other things) a table visual with columns from two different tables, and measures. Using the similar dummy data to last time here are some tables to illustrate:

 

Customer:

Customer RegionCustomer SegmentCustomer Name
EuropeIndustrialFoo
EuropeIndustrialBar
AmericasTechBaz

 

Product:

Product NumberProduct Category
AHats
BShoes
CShoes


Sales:

Product NumberCustomer NameUnits Sold
AFoo10
ABar5
BBaz5
BBar12
CFoo7
CBaz2

 

So I have a measure which calculates the total sales (in fact its a bit more complicated but this shouldn't affect things, I hope), and in my table visual any of the non-numeric columns might appear based on the field parameter. What I want to do is calculate the average of this total measure at a regional level with respect to the fields currently selected. This won't actually be showing in the table, its an intermediate in other calcualtions, but I'll show it in my example below to explain the value I need.

So for example with [Customer Region] and [Product Category] selected we would see:

 

Customer RegionProduct CategoryTotal SalesAverage Sales
EuropeHats1513.7
EuropeShoes1913.7
AmericasShoes713.7

 

I have tried using AVERAGEX here but since the columns selected can change (and come from two different tables!) I'm not sure what to include as the first parameter. My instinct suggests I need a DAX formula that returns a table identical to the table visual to iterate over, but I can't figure out how to do this. Any ideas?

2 REPLIES 2
v-kongfanf-msft
Community Support
Community Support

Hi @Connor888 ,

 

Maybe you can try below formula to create calculated table:

Table =
VAR total_ =
    CALCULATE ( SUM ( Sales[Units Sold] ) )
VAR table_ =
    SUMMARIZE ( Sales, [Customer Region], [Product Category] )
VAR result =
    SUMMARIZE (
        Sales,
        [Customer Region],
        [Product Category],
        "category_total", CALCULATE ( SUM ( Sales[Units Sold] ) ),
        "avg",
            DIVIDE (
                CALCULATE ( SUM ( Sales[Units Sold] ), ALL ( Sales ) ),
                COUNTROWS ( table_ )
            )
    )
RETURN
    result

vkongfanfmsft_0-1714465192772.png

Best Regards,
Adamk Kong

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi, this would work if I was just using a static selection of columns, but I have a field parameter involved so it may not be [Customer Region] and [Product Category], it could be any combination of dimensions. 

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.

Top Solution Authors