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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
jruf
Frequent Visitor

Calculate average by category where the averages respond to slicers

Hi there,

 

I'm sure this is a basic question but I haven't been able to solve it. 

 

I have a table with three variables, "date", "country" and "price". I just want to produce a new table which calculates the average price across countries, but where the values update depending on a slicer for "date". 

 

E.g. see first table below for example input table and example of what the output should look like

 

Input table

datecountryprice
1/1/21USA20
1/2/21USA

30

1/3/21USA40
1/1/21England10
1/2/21England20
1/3/21England30

 

What I want the output table to look like (assuming all dates are selected in the date slicer)

countryprice
USA30
England20

 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @jruf 

 

Unfortunately, a Calculated Table is evaluated upon refresh of the datamodel. Thus selecting a slicervalue doesn't return a new evaluated calculated table.

Table:

Table 2 =
SUMMARIZE (
    'Table',
    'Table'[country],
    "price",
        CALCULATE (
            AVERAGE ( 'Table'[price] ),
            ALLEXCEPT ( 'Table', 'Table'[date], 'Table'[country] )
        )
)

This is a fixed table.

vzhangti_0-1661849534937.png

 

You can try the following methods.

Measure:

Measure =
CALCULATE (
    AVERAGE ( 'Table'[price] ),
    ALLEXCEPT ( 'Table', 'Table'[country], 'Table'[date] )
)

vzhangti_1-1661849759493.pngvzhangti_2-1661849773549.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @jruf 

 

Unfortunately, a Calculated Table is evaluated upon refresh of the datamodel. Thus selecting a slicervalue doesn't return a new evaluated calculated table.

Table:

Table 2 =
SUMMARIZE (
    'Table',
    'Table'[country],
    "price",
        CALCULATE (
            AVERAGE ( 'Table'[price] ),
            ALLEXCEPT ( 'Table', 'Table'[date], 'Table'[country] )
        )
)

This is a fixed table.

vzhangti_0-1661849534937.png

 

You can try the following methods.

Measure:

Measure =
CALCULATE (
    AVERAGE ( 'Table'[price] ),
    ALLEXCEPT ( 'Table', 'Table'[country], 'Table'[date] )
)

vzhangti_1-1661849759493.pngvzhangti_2-1661849773549.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish Mathur,

 

Thanks a bunch for this.

 

I should have been more specific in my question, but I want the output table which averages price by country to be a table in the same vein as the "calendar" and "data" tables you created - a dataset which appears in the 'fields' pane which I can reference in additional calculations. Are you able to advise on how I can do this?

 

Thanks again

Jon    

You are welcome.  I prefer not to use calculated table formulas.  Someone else will help you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.