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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Employee
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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