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
Terp
Advocate III
Advocate III

Calculated Column: Return Two (2) Characters After Comma

I was trying to figure out how to do a reverse concantination, per se, and got close...but can't get it right. 🙂

 

I have a long string of city/MSA information and I want to join this city table to another (state-level) table and decided to use 'State Abbreviation' as the bridge...used a bunch of SWITCHes to make "Flordia" become "FL" in a new column, for example.

 

So in short, I want to take the value in the [City/MSA/MD] column and truncate it to return the first two letters after/to the right of the comma, which will form the 'State Abbreviation' column.

 

You can see I got the "FL" in there perfectly...but also everything thereafter. 🙂

 

Could someone point out the error in my ways, please? Should I use something else (lookups?) to get at the two letters after the comma? 

 

(I don't even want to address the MSAs that comprise MULTIPLE states, so just pulling the first two capital letters after the comma and assigning to that primary state...for now). lol

 

Terp_1-1655947483134.png

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Terp , On Top of your formula use left(<Current formula>,2)

I think that might help

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

5 REPLIES 5
MPetramalo214
Helper I
Helper I

Can you try adding the LEFT function to what you already have? 

St Abbrv = 
LEFT (
    RIGHT ( [City/MSA/MD], LEN ( [City/MSA/MD] ) - FIND ( ", ", [City/MSA/MD] ) - 1 ),
    2
)

 This should get you the two characters on the left, of the text to the right of the comma. 

 

If you have a static number of states that an entry can be at most (ie. no more than two/three states), you could probably add a conditional to check the third digit from the left, and if its a "-" then you have two states, and return the first 5 characters, otherwise return the first 2.

Your genius is equally impressive, thanks! 🙂

 

'Left (right...' just didn't seem right. Thank you both for the help...never would have stumbbled on that one.

It does seem like a strange combination.. I went ahead and threw together a mockup of how you could go about getting multiple states.  This will only work if you have a static number of states; if its dynamic, then a bunch of nested if statements probably isn't efficient enough.

MPetramalo214_0-1655950113612.png

St Abbrv = 
var rightOfComma = RIGHT([Column2], LEN([Column2]) - FIND(", ", [Column2])-1)

var thirdChar = RIGHT(LEFT(rightOfComma, 3), 1)

return
IF(
    thirdChar = "-",
    LEFT(rightOfComma, 5),
    LEFT(rightOfComma, 2)
)
amitchandak
Super User
Super User

@Terp , On Top of your formula use left(<Current formula>,2)

I think that might help

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

You, sir, are a genius....would have NEVER gotten that one right...did swap out right for left previously and played around, but would have never thought to use both. 🙂

 

It doen't seem intuitive/efficient, but it sure works! Many, many thanks, sir!

 

Terp_0-1655949718398.png

 

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.