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
GB08
New Member

IF Statement using Text Column

Hello, 

I want to use an IF Statement on a text column to return certain values/calculations from another column.

 

For example, 

If Column 'Name' = "New" then Calculate(Total_Value*12) else (Total_Value)

 

I haven't been able to figure out how to do this.

I tried this but get an error for Max function only accepts a column reference as an argument

Value = IF(MAX('Value Table'[Name]="New"),[Total_Value*12],[Total Value])
 
Any help would be greatly appreciated.
1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

@GB08 , It would be like this:-

Value =
SWITCH (
    TRUE (),
    MAX ( 'Value Table'[Name] ) = "New", [Total_Value] * 12,
    MAX ( 'Value Table'[Name] ) = "Old", [Total_Value] / 12,
    [Total Value]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

4 REPLIES 4
Samarth_18
Community Champion
Community Champion

Hi @GB08 ,

 

Ideal code what your trying would be like this:-

Value = IF(MAX('Value Table'[Name])="New",[Total_Value]*12,[Total Value])

I am considering [Total_value] as some already created measure.

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi @Samarth_18 

 

Thank you for this, it works perfectly!

One further question if that is ok... is it also possible to have two IF statements in this Measure?

 

For example -

If Column 'Name' = "New" then Calculate(Total_Value*12)

or

If Column 'Name' = "Old" then Calculate(Total_Value/12)

else (Total_Value)

 

Thank you for your speedy reply and help 🙂

Samarth_18
Community Champion
Community Champion

@GB08 , It would be like this:-

Value =
SWITCH (
    TRUE (),
    MAX ( 'Value Table'[Name] ) = "New", [Total_Value] * 12,
    MAX ( 'Value Table'[Name] ) = "Old", [Total_Value] / 12,
    [Total Value]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Super @Samarth_18 

 

This works perfect... I must try to learn more about the SWITCH function! 

 

Thank you for your help! 🙂

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.