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

Inserting a dash based on certain criteria in Power BI

Hello,

 

Hope someone can help with this.

 

I've got a column in Power BI that has aircraft registrations but they are without the required dash separator as shown the screenshot

 

mkwiatkowski_0-1639405642720.png

 

What I would like to be able to do is create another column and have some way of adding the dash in but based on certain criteria depending on the registration. E.g.

 

If Regno starts with OOxxx then OO-xxx

If Regno starts with Dxxxx then D-xxxx

If Regno start with YUxxx then YU-xxx

and so on..

 

Tried conditional columns but that doesn't work. Was thinking along the lines of a custom column that inserts a dash but this inserts the dash at an arbutry position and not depending on the type of registration condition:

 

= Table.AddColumn(#"Changed Type1", "Custom2", each Text.Insert(Text.From([REGNO]),2,"-"))

 

Any thoughts or suggestions would be much appreciated

 

 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @mkwiatkowski ,

 

You can try to create a new column like below:

Column = 
var left_1 = LEFT('Table'[Regno],1)
var left_2 = LEFT('Table'[Regno],2)
VAR right_1 = SUBSTITUTE('Table'[Regno],left_1,"")
var right_2 = SUBSTITUTE('Table'[Regno],left_2,"")
return SWITCH(TRUE(),
                left_1 IN {"D","L"},COMBINEVALUES ( "-", left_1, right_1 ),
                left_2 IN {"OO","YU"},COMBINEVALUES ( "-", left_2, right_2 ))

Vlianlmsft_0-1639634006088.png

 


Best Regards,
Liang
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

1 REPLY 1
V-lianl-msft
Community Support
Community Support

Hi @mkwiatkowski ,

 

You can try to create a new column like below:

Column = 
var left_1 = LEFT('Table'[Regno],1)
var left_2 = LEFT('Table'[Regno],2)
VAR right_1 = SUBSTITUTE('Table'[Regno],left_1,"")
var right_2 = SUBSTITUTE('Table'[Regno],left_2,"")
return SWITCH(TRUE(),
                left_1 IN {"D","L"},COMBINEVALUES ( "-", left_1, right_1 ),
                left_2 IN {"OO","YU"},COMBINEVALUES ( "-", left_2, right_2 ))

Vlianlmsft_0-1639634006088.png

 


Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.