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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculating DAX based of table row

Hello,

 

I want to create a DAX that will execute a expression based on the table rows. My measure is 

Over Spec = CALCULATE( COUNTROWS( FILTER((Infinity), [Value] > 3.6)) , Infinity[Test] = "Shoulder Weight") + CALCULATE( COUNTROWS( FILTER((Infinity), [Value] > 1.4)) , Infinity[Test] = "Body Weight")
 
Only Shoulder Weight and Body Weight should have values when evaluating this measure. 
 
 

 

PBI 1.png

 

Thanks

1 ACCEPTED SOLUTION

Please see this post to learn more about KEEPFILTERS().

https://www.sqlbi.com/articles/using-keepfilters-in-dax/

One of the example in that article shows the syntax like below.  Is that how you used it?

 

OnlyRed :=
CALCULATE (
    [Sales Amount],
    KEEPFILTERS ( Products[Color] = "Red" )
 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
mahoneypat
Microsoft Employee
Microsoft Employee

Your calculate filter on Infinity[Test] is overwriting the filter provided by the row on the table visual.  Wrap it in

KEEPFILTERS() to get your desired effect.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

This is the error I get when wrapping measure in KeepFilters 

 

KEEPFILTERS function can only be used as a top level filter argument of CALCULATE and CALCULATETABLE or with a table argument of a function performing a table scan.

Please see this post to learn more about KEEPFILTERS().

https://www.sqlbi.com/articles/using-keepfilters-in-dax/

One of the example in that article shows the syntax like below.  Is that how you used it?

 

OnlyRed :=
CALCULATE (
    [Sales Amount],
    KEEPFILTERS ( Products[Color] = "Red" )
 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


az38
Community Champion
Community Champion

Hi @Anonymous 

try more easy

Over Spec = 
CALCULATE( COUNTROWS(Infinity), Infinity[Value] > 3.6, Infinity[Test] = "Shoulder Weight")
 + 
CALCULATE( COUNTROWS(Infinity), Infinity[Value] > 1.4, Infinity[Test] = "Body Weight")

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

The result using that measure is PBI 1.png

 

I need the over column to calculate based on test column

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.