cancel
Showing results for
Did you mean:
Regular Visitor

## Calculation of averages using data from two different columns as filters.

Afternoon,

I have 3 columns, in first - different products, in second - country of origin, in third - wieght of the product (number).

Is it possible to calculate average value of each product for each country separately?

Something like this (in last column is what I want to achieve):

 Fruit_type Country weight Arith_weight_average_by_fruit_type_and_country apples Spain 2 3 apples Spain 3 3 apples Spain 4 3 grapes Italy 1 1.5 grapes Italy 2 1.5 apples Norway 3 3.5 apples Norway 4 3.5 pineapple Peru 5 5.33 pineapple Peru 6 5.33 pineapple Peru 5 5.33

Any hints / Tips apreciated, thanks

1 ACCEPTED SOLUTION
Super User

Hi @ak_rafa ,

You can use this measure:

AvgW =
VAR currentFruit = SELECTEDVALUE ( T[Fruit_type] )
VAR currentCountry = SELECTEDVALUE ( T[Country] )
RETURN
AVERAGEX (
FILTER (
ALL ( T ),
T[Fruit_type] = currentFruit && T[Country] = currentCountry
),
T[weight]
)

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

4 REPLIES 4
Community Support

Hi @ak_rafa,

Did the above suggestions help with your requirement? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Super User

Hi @ak_rafa ,

You can use this measure:

AvgW =
VAR currentFruit = SELECTEDVALUE ( T[Fruit_type] )
VAR currentCountry = SELECTEDVALUE ( T[Country] )
RETURN
AVERAGEX (
FILTER (
ALL ( T ),
T[Fruit_type] = currentFruit && T[Country] = currentCountry
),
T[weight]
)

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

Super User

@ak_rafa , a new column

col = averagex(filter(Table, [Fruit_type] = earlier([Fruit_type] )) , [weight])

Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!
Regular Visitor

@amitchandak  many thanks for helping me out. It solves half of my issue.

By using the expression that you have provided i got average weight by fruit_type. But it has averaged the fruits from different country.
Making it short - i need to apply 2 filters: by fruit type and by country.

Any clues how it can be done?

Announcements

#### Launching new user group features

Learn how to create your own user groups today!