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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Anonymous
Not applicable

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.

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

 

 

Anonymous
Not applicable

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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.