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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
airportplanner
Frequent Visitor

IF statement with LEN, LEFT & RIGHT formulas

Hello, new to Power Bi, sorry if this is a basic question.

 

I have a column with 2 types of data (lets call it Flight No Colunn) : BA254/BA879 and BA463/548

 

I have created a helper column that returns the length of each cell (11 or 9)

 

I would like to create an if command like this:

 

IF(LEN[Flight No Column]=11, RIGHT[Flight No Column, 5], CONCATENATE(LEFT([Flight No Column], 2), RIGHT([Flight No Column], 5))

 

However, this does not work as I am combining numbers with text in the same formula.

 

Do you have any suggestions?

 

Thank you very much

 

 

 

1 ACCEPTED SOLUTION

i only changed the position of the parentheses

 2018-06-20_8-53-43.png

Column 2 = IF(LEN(Table1[Flight No Column]) =11, RIGHT(Table1[Flight No Column], 5), CONCATENATE(LEFT(Table1[Flight No Column], 2), RIGHT(Table1[Flight No Column], 3))

View solution in original post

10 REPLIES 10
BKirsch12
Resolver II
Resolver II

Can you provide an example of the output you are looking for in both scenarios (LEN 9 and 11). I ran your code, adding the appropriate () and this is the result:

 

CONCAT.PNG

Thank you for your time. Trying to replicate your code i get this

 

tttttt.PNG

if (LEN(Table1[Column]) = 11, right(Table1[Column],5), CONCATENATE(left(Table1[Column],2),RIGHT(Table1[Column],3)))

is the correct function

With the above code, I can not go to the second step of the if command as shown here:

 

tttttttttt.png

 

 

I am still failing to write down the correct syntax.

 

Can i kindly ask you to upload your functional Power Bi file?

Can you please share the yellow error message in the screenshot. Also try to copy/paste this :

Column = if (LEN(Table1[Flight No Column]) = 11, right(Table1[Flight No Column],5), CONCATENATE(left(Table1[Flight No Column],2),RIGHT(Table1[Flight No Column],3)))

@NipponSahoreunfortunately your code is not working

 

I can not replicate the working example from @BKirsch12

 

I am uploading my file, would you mind taking a look ?

 

https://drive.google.com/open?id=1Tki-_fl_X6HqY2Ea9bV4fV-Je_nxEzQP

 

The error I am getting is this one:

 

error.PNG

i only changed the position of the parentheses

 2018-06-20_8-53-43.png

Column 2 = IF(LEN(Table1[Flight No Column]) =11, RIGHT(Table1[Flight No Column], 5), CONCATENATE(LEFT(Table1[Flight No Column], 2), RIGHT(Table1[Flight No Column], 3))

Yes Nippon is right, the issue is your LEN function needs to return a value before it can be compared to 11.

Thank you both.

 

My final working code is:

 

Column 2 = IF((LEN(Table1[Flight No Column]) =11), RIGHT(Table1[Flight No Column], 5), CONCATENATE(LEFT(Table1[Flight No Column], 2), RIGHT(Table1[Flight No Column], 3)))

The problem is the LEN function. This is what you had in the file you sent:

 

Column 2 = IF(LEN(Table1[Flight No Column] =11), RIGHT(Table1[Flight No Column], 5), CONCATENATE(LEFT(Table1[Flight No Column], 2), RIGHT(Table1[Flight No Column], 3))) 

The length (LEN) function needs to return a value before it can be compared to another number. This is how it should be:  

 

Column 2 = IF(LEN(Table1[Flight No Column]) =11, RIGHT(Table1[Flight No Column], 5), CONCATENATE(LEFT(Table1[Flight No Column], 2), RIGHT(Table1[Flight No Column], 3)))

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.