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
martti
Helper I
Helper I

Measure to calculate only for certain non-numeric values

I have a measure that calculates a result from multiple different measures for different employees, e.g.

Measure0 = 
(
    [Measure1] +
    [Measure2]
) / 2 +
[Measure3]

My intent is for Measure3 to only be calculated if the employee belongs in a certain group. E.g.

Measure0 = 
(
    [Measure1] +
    [Measure2]
) / 2 +
IF(
    Tbl_employees[Group]="Group1" ;
    [Measure3] ;
    0
)

 But I cannot use the IF statement like that, it'd have to be like sum of groups in the employees table, but that is illogical. Is there a way to apply the measure calculation for only certain non-numeric values?

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @martti ,

 

When using measures you need to be aware that you cannot reference tables/column directly and you need to use aggregators in your case if you use the MAX function for the if statment that should work.

 

Measure0 =
 ( [Measure1] + [Measure2] ) / 2
    + IF ( MAX ( Tbl_employees[Group] ) = "Group1"; [Measure3]; 0 )

 

You can also try this variant of the calculation should work in the same way:

 

Measure0 =
( [Measure1] + [Measure2] ) / 2
    + CALCULATE (
        [Measure3];
        FILTER (
             Tbl_employees;
            Tbl_employees[Group] ="Group1"
        )
    )

 

Regards,

MFelix 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @martti ,

 

When using measures you need to be aware that you cannot reference tables/column directly and you need to use aggregators in your case if you use the MAX function for the if statment that should work.

 

Measure0 =
 ( [Measure1] + [Measure2] ) / 2
    + IF ( MAX ( Tbl_employees[Group] ) = "Group1"; [Measure3]; 0 )

 

You can also try this variant of the calculation should work in the same way:

 

Measure0 =
( [Measure1] + [Measure2] ) / 2
    + CALCULATE (
        [Measure3];
        FILTER (
             Tbl_employees;
            Tbl_employees[Group] ="Group1"
        )
    )

 

Regards,

MFelix 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



I figured that referencing to the column directly would not be an option, but never thought about using MAX() for the reference. It worked exactly as intended, thanks!

Hi @martti ,

 

You can also use SELECTEDVALUE, MIN, or other similar notation.

 

However not really sure how you want to present the information but if you want to have it in a table you need to use the second formula I presented since the sum of the values using the IF statement will get you an incorrect result due to context.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.