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

Replace Calculated Measure With "New" When Year over Year = -100 (SQL Case When)

Hello, I am new to PowerBI and learning. I created calculated measures for Product Revenue TY and PR LY, with one more for YoY PR. In my YoY PR column, I have a bunch of -100% because there are some new products in the table this year. I'm wondering how I can simply replace the -100%'s with "New" to make it look cleaner. I know in sql you can use a case when statement to replace the values, i'm lost on how to do it here. 

 

Please note these are calculated measures, not tables.

 

Calculations: 

 

Product Revenue This Year: 

PRTY =
VAR
CurrentDate = [Date Reference]
RETURN
CALCULATE(SUM(Dashboards_Merch[Product Revenue]),Dashboards_Merch[Order_Year] = YEAR(CurrentDate))
 
Product Revenue Last Year:
PRLY =
VAR
CurrentDate = [Date Reference]
RETURN
CALCULATE(
SUM(Dashboards_Merch[Product Revenue]),
Dashboards_Merch[Order_Year] = YEAR(CurrentDate)-1
)
 
YoY PR: 
YoY PR = DIVIDE([PRTY], [PRLY], 0)-1
1 ACCEPTED SOLUTION

HI @ehanson2,

You can add if statement with the condition to compare with static value and return the result.

Measure =
IF([YoY PR] = -1,"New",[YoY PR]&"")

Notice: measure not support to return different type of values at the same time, if you want to use both text and numeric value, please change numeric to text first.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

Well, if you tried that, you would probably get an error about variant data types. You would need to replace with a number like 0 or BLANK:

 

Measure =

  VAR __Variable = <code>

RETURN

  IF(__Variable = -1,BLANK,__Variable)


@ 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 having trouble getting this to work. what am i missing here? The RETURN part throws an "unexpected expression" 

Measure =

  [YoY PR] = (DIVIDE([PRTY], [PRLY], 0)-1)

RETURN

  IF([YoY PR] = -1,BLANK,[YoY PR])

HI @ehanson2,

You can add if statement with the condition to compare with static value and return the result.

Measure =
IF([YoY PR] = -1,"New",[YoY PR]&"")

Notice: measure not support to return different type of values at the same time, if you want to use both text and numeric value, please change numeric to text first.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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
Top Kudoed Authors