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

Create a calculated column based on string start and length

Hi, i have a bunch of strings (serial numbers) and i want to categorize them accordingly with a new calculated column

The lenght is important to me, only if the serial starts with AA.
Really hope you can help

 

InputDesired output
AA12345678910AA-long
AA1234AA-Short
AA12345678911AA-Long
AA1235AA-Short
BB123212 
2 ACCEPTED SOLUTIONS
v-yiruan-msft
Community Support
Community Support

Hi @FrederikAhring ,

You can create a calculated column as below to get it:

Desired output =
IF (
    LEFT ( 'Table'[Input], 2 ) = "AA",
    IF ( LEN ( 'Table'[Input] ) <= 6, "AA-Short", "AA-Long" ),
    BLANK ()
)

yingyinr_0-1650338341311.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thanks a lot @v-yiruan-msft.

It seems to work perfectly

View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @FrederikAhring ,

You can create a calculated column as below to get it:

Desired output =
IF (
    LEFT ( 'Table'[Input], 2 ) = "AA",
    IF ( LEN ( 'Table'[Input] ) <= 6, "AA-Short", "AA-Long" ),
    BLANK ()
)

yingyinr_0-1650338341311.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks a lot @v-yiruan-msft.

It seems to work perfectly

DataInsights
Super User
Super User

@FrederikAhring,

 

Try this custom column in Power Query:

 

if Text.Start([Input], 2) = "AA" then
  if Text.Length(Text.Middle([Input], 3, Text.Length([Input]))) > 4 then
    "AA-Long"
  else
    "AA-Short"
else
  null

 

DataInsights_0-1650291087183.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.