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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
dwade
New Member

Issues with filtering when a specific measure is applied

I have a specific data structure which I can share here, basically the data consists of individual reviews and aggregate reviews by specific companies and the various subordinates within each company. A company can belong to one or many Departments which in turn can belong to one or many Organisations which are mapped using a reference table called 'Account'.

dwade_0-1709002849836.png

 

I have the following table, just a very simple one:

 

dwade_1-1709003499963.png

 

And I can filter it by "Department" which certain Companies belong to:

dwade_2-1709003614007.png

 

OK great, that's fine.

But when I add this measure:

 

Month vs Average = IF(ISBLANK([Average Rating Past Month]), "No reviews past month",Review[Average Rating Past Month] - OverallRating[Overall Average Rating])

 

 

It works as expected without filters:

dwade_3-1709003804909.png

 

But it breaks the same filter as I was using earlier:

dwade_5-1709003927155.png

 

 

I understand this has something to do with filter context and seems to be triggered by using either IF ISBLANK, or IF <= 0 and such which I sort of see why. But after spending a couple of days trying to work around, I'm at a loss.

Can anyone shed some light on the best practices for approaching this problem and getting around it?

Thanks,

1 ACCEPTED SOLUTION
v-huijiey-msft
Community Support
Community Support

Hi @dwade ,

 

As you correctly point out, this issue is related to the filter context. When filters are applied, they change the context in which the metric is calculated.

 

Please try:

MonthVSAverage = 
VAR SelectedDepartment = SELECTEDVALUE('Department'[DepartmentName])
RETURN
IF(
    SelectedDepartment = "A",
    CALCULATE(
        IF(
            ISBLANK(MAX('Table'[Average Rating Past Month])), 
            "No reviews past month",
            MAX('Table'[Average Rating Past Month]) - MAX('Table'[Overall Average Rating])
        ),
        'Department'[DepartmentName] = SelectedDepartment
    )
)

 

You can change 'SelectedDepartment' to whatever data you have in the Filter, in this case 'A' 'B' 'C'.

 

I know it is a bit of a pain in the ass but it is an alternative.

 

The result is ideal.

vhuijieymsft_0-1709104577228.png

vhuijieymsft_1-1709104577232.png

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

2 REPLIES 2
v-huijiey-msft
Community Support
Community Support

Hi @dwade ,

 

As you correctly point out, this issue is related to the filter context. When filters are applied, they change the context in which the metric is calculated.

 

Please try:

MonthVSAverage = 
VAR SelectedDepartment = SELECTEDVALUE('Department'[DepartmentName])
RETURN
IF(
    SelectedDepartment = "A",
    CALCULATE(
        IF(
            ISBLANK(MAX('Table'[Average Rating Past Month])), 
            "No reviews past month",
            MAX('Table'[Average Rating Past Month]) - MAX('Table'[Overall Average Rating])
        ),
        'Department'[DepartmentName] = SelectedDepartment
    )
)

 

You can change 'SelectedDepartment' to whatever data you have in the Filter, in this case 'A' 'B' 'C'.

 

I know it is a bit of a pain in the ass but it is an alternative.

 

The result is ideal.

vhuijieymsft_0-1709104577228.png

vhuijieymsft_1-1709104577232.png

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hi @v-huijiey-msft ,

 

Yes that worked! It is unfortunate that the SelectedDepartment needs to be predefined because that makes things tricky but I can probably work around it.

Thanks for your help 🙂 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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