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
dalmn21
Frequent Visitor

IF Statement

Hi,

 

I am fairly new to DAX and spent some time finding ways to fix my issue before posting here! I am wanting to create a measure to put into a scorecard that shows the percent change depending on what name and day is chosen. This report is updated daily. 

 

For example:

If I choose "ABC" then it would use an equation I created for A (eq_ABC) else it would show the result for B (eq_DEF)

I've tried using this measure I created and it works to an extent. When ABC is chosen, it will show the results for Eq_ABC. When DEF is chosen, it still uses Eq_ABC for some reason. 

IF(CONTAINS(Main , Main[Name], "ABC"), Main[Eq_DEF], Main[Eq_ABC])

 

I've tried creating a calculated column, but it doesn't give me a percentage for a given day that has been chosen. It summarizes it (I changed it to don't summarize, but I also don't need the average, count, and min/max). 

IF(Main[Name] = "ABC", Main[Eq_ABC], Main[Eq_DEF])
 
Thanks in advance! 
5 REPLIES 5
LQuedas
Resolver II
Resolver II

@dalmn21 ,

 

you can try to use variables, try this example:

 

NewMeasure =
var _f1 = count('Product'[Product Name])
var _f2 = 1000
return if(CONTAINS('Product','Product'[Product Name],"Product A"),_f1,_f2)

LQuedas_0-1674661465012.png

this measure uses only the _f1 formula to the product A

 

Hope this helps

 

Cheers, LQ

@LQuedas 

 

Thank you for the reply! Unfortunately, I get the same result as one of my examples where the second name option is using the incorrect equation. 

Greg_Deckler
Super User
Super User

@dalmn21 Maybe:

Measure = IF(MAX(Main[Name]) = "ABC", Main[Eq_ABC], Main[Eq_DEF])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

I'm getting a "The MAX function only accepts a column reference as an argument" error. 

@dalmn21 If that is a measure ( [Name] ), then just drop the MAX and reference the measure directly (no need to specify the table). Otherwise, you could try MAXX which accepts a table expression.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors