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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mattterriault
Frequent Visitor

Apply Filter Before Calculation

The formula I have below works but not when I do a filter. I am trying to get the lowest value in a group and assign a 1 to it and 0 when it is not the lowest value. Can I add a If filtered or something to this column formula to make it look for the lowest of all the ones filtered not the entie table. Thanks for any help!

 

A = dataset

B = The score by row at the aggregated view desired

C = after the formuala is applied that works but, If I were to take out, for example Company B, Distance "Far" , Size "B" , it would keep all the other companys at zero because the formula is still looking over the entire dataset and for some reason is not looking at the company filter I have in place.

D = What I am hoping it to look like

 

the formula calculating this is:

 

Column = 
var _minvalue = 
MINX(
    FILTER(
        ALLSELECTED('Table'),
        'Table'[Size]=EARLIER('Table'[Size])
        &&'Table'[Distance]=EARLIER('Table'[Distance])),
        'Table'[score])
return
IF(
    'Table'[score] = _minvalue,1,0)

 

 

sample5.jpg

1 ACCEPTED SOLUTION

Hi @mattterriault ,

Please create another new measure with below formula to replace the measure [Lowest Value] on the matrix:

Measure =
SUMX (
    VALUES ( 'Table'[Distance] ),
    SUMX ( VALUES ( 'Table'[Distance] ), [Lowest Value] )
)

Or you can refer the method to fix the incorrect total value problem:

Power BI: Totals Incorrect

Fixing Incorrect Measure Totals

Why Your Total Is Incorrect In Power BI

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

Community Support Team _ Rena
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
DataInsights
Super User
Super User

@mattterriault,

 

Try this measure. The reason that your calculated column did not work properly is that calculated columns are not affected by filter context.

 

Lowest Value =
VAR vScore =
    MAX ( Table[Score] )
VAR vGroupMinValue =
    CALCULATE ( MIN ( Table[Score] ), ALLSELECTED ( Table[Company] ) )
VAR vResult =
    IF ( vScore = vGroupMinValue, 1, 0 )
RETURN
    vResult

 

 

DataInsights_0-1605457344095.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you for responding. This works but it does not roll it up like the column calculation. The ultimate goal is to say " out of what is selected, how many times was company A the lowest, how many times was company B the lowest, etc....". I would like to not even have distance and size in the view, just the sum of the calculation you provided. Thanks again, I know I didnt clarify all that at the beginning.

 

columnVSmeasure1.jpg

 

 

Hi @mattterriault ,

Please create another new measure with below formula to replace the measure [Lowest Value] on the matrix:

Measure =
SUMX (
    VALUES ( 'Table'[Distance] ),
    SUMX ( VALUES ( 'Table'[Distance] ), [Lowest Value] )
)

Or you can refer the method to fix the incorrect total value problem:

Power BI: Totals Incorrect

Fixing Incorrect Measure Totals

Why Your Total Is Incorrect In Power BI

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

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

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!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.