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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Calculate the Average of values if filters are selcted else use the value for the whol

Hi,

 

I try to cerate a measure wich should calcualte the average number of the selected regions (via Chiclet Slicer).

2021-02-17 11_23_06-Greenshot.png

If there is no filter set it should take the value of the whole country (CH - which is also part of this table).

 

In terms of logic, it should read something like this: If FilterIsActive take the average of median_R_mean of the selected regions else select the median_R_mean of "CH".

 

I have tried this : 

RE = IF(ISFILTERED(Region[Bezeichnung]), AVERAGE(COVID19Re_geoRegion_Last_value[median_R_mean]), FILTER(COVID19Re_geoRegion_Last_value, "CH"))
 
Unfortunately this approach does not work.
Can anyone help me on what possible approach I can follow here?
 
Thanks a lot.

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

You cannot use the Filter() function directly in IF statement, basically the formula should be like this:

RE =
IF (
    ISFILTERED ( 'Table'[geoRegion] ),
    AVERAGE ( 'Table'[median_R_mean] ),
    CALCULATE (
        AVERAGE ( 'Table'[median_R_mean] ),
        FILTER ( 'Table', 'Table'[geoRegion] = "CH" )
    )
)

1.png2.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
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

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Try a measure like

RE = IF(ISFILTERED(Region[Bezeichnung]), AVERAGE(COVID19Re_geoRegion_Last_value[median_R_mean]), calculate(AVERAGE(COVID19Re_geoRegion_Last_value[median_R_mean]),FILTER(COVID19Re_geoRegion_Last_value, "CH")))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi admitchandak

 

Thanks for your help, now it works partly. It will calculate the average of the selected regions.

But for the else statement it does not work. There is no average calculation needed, only a filtering by CH (will show the value of the Row CH in this case 0.89).

 

But somehow it does not accept Filter (FILTER(COVID19Re_geoRegion_Last_value, "CH")).

Do you now how I can make it work? Thanks again

Hi @Anonymous ,

You cannot use the Filter() function directly in IF statement, basically the formula should be like this:

RE =
IF (
    ISFILTERED ( 'Table'[geoRegion] ),
    AVERAGE ( 'Table'[median_R_mean] ),
    CALCULATE (
        AVERAGE ( 'Table'[median_R_mean] ),
        FILTER ( 'Table', 'Table'[geoRegion] = "CH" )
    )
)

1.png2.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors