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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.