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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register 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
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.