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
WtP
New Member

create a new column with IP addresses, based on column with different values with IP address in them

I have a log overview from a firewall. What I want to achieve is to split the IP addresses from the source column into a seperate column. But here is where it gets tricky. The column source looks like below:

Source

192.168.2.150

Asset A (192.168.6.40)

host-192.168.2.50 (192.168.9.50)
hostb.examplecorp.com (192.168.4.60)
asset-v525-192.168.2.88 (192.168.1.88)

 

What I would like to have is the following:

SourceSource IP address

192.168.2.150

192.168.2.150

Asset A (192.168.6.40)

192.168.6.40

host-192.168.9.50 (192.168.9.50)192.168.9.50
hostb.examplecorp.com (192.168.4.60)192.168.4.60
asset-v525-192.168.1.88 (192.168.1.88)192.168.1.88

As you would understand the IP addresses are there as an example and do not reflect the actual ranges. The IP addresses do differ.

 

I mainly was trying this in DAX using the left and right command which gives me different results all not what I need. I also tried my way through this using power query. This also worked kind of. the IP addresses could be split by the "(" but then the cells with only an IP address would stay. Adding an "(" in from of all IP adresses also resulted in a lot of issues like i.e.: host-(192, ((192, asset-v525-(192, etc.

 

hope you can help me because I have no clue where else to look for answers.

 

This will be my last ditch effort. If this doesn't work, I'll start splitting data at the source document level. (I am trying to avoid this)

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@WtP 

Here is a workaround for you.

create a column from example

1.PNG

then you type in the expected output one by one, it will automatically help you extract the data. You need to modify the one that does not display the expected output.

2.PNG





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

Proud to be a Super User!




View solution in original post

v-yanjiang-msft
Community Support
Community Support

Hi @WtP ,

According to your description, here's my solution. Create a custom column.

vkalyjmsft_0-1666677573948.png

if Text.Contains([Source],"(") then Text.BetweenDelimiters([Source], "(", ")") else [Source]

Get the result.

vkalyjmsft_1-1666677590617.png

Here's the whole M syntax.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrQ00jM0s9ADkqYGSrE60UqOxcWpJQqOChowKTM9EwNNsFRGfnGJLkKHqQFCkSWQh1CUpJdakZhbkJOanF9UoJecn4tQaKJnBlWYCLJIt8zUyBTJTAsLhFJDIA+oNBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Source", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Source],"(") then Text.BetweenDelimiters([Source], "(", ")") else [Source])
in
    #"Added Custom"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

5 REPLIES 5
v-yanjiang-msft
Community Support
Community Support

Hi @WtP ,

According to your description, here's my solution. Create a custom column.

vkalyjmsft_0-1666677573948.png

if Text.Contains([Source],"(") then Text.BetweenDelimiters([Source], "(", ")") else [Source]

Get the result.

vkalyjmsft_1-1666677590617.png

Here's the whole M syntax.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMrQ00jM0s9ADkqYGSrE60UqOxcWpJQqOChowKTM9EwNNsFRGfnGJLkKHqQFCkSWQh1CUpJdakZhbkJOanF9UoJecn4tQaKJnBlWYCLJIt8zUyBTJTAsLhFJDIA+oNBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Source = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Source", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if Text.Contains([Source],"(") then Text.BetweenDelimiters([Source], "(", ")") else [Source])
in
    #"Added Custom"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Hi @v-yanjiang-msft ,

 

Thank you for your reply. It was very helpfull.

 

As I am new to the whole PowerBI what would be the difference between the first syntax and the M syntax? and if I have to use the M syntax, where do I have to put it?

 

Thank you in advance.

Hi @WtP ,

My pleasure!

Please follow the steps:

1.In Desktop, select Transform data.

vkalyjmsft_0-1666690057648.png

2.In Power Query, right-click the blank field under Queries, select New Query>Blank Query.

vkalyjmsft_1-1666690077034.png

3.Click Advanced Editor, then copy-paste the whole M syntax I provided in the previous post to see the details.

vkalyjmsft_2-1666690098958.png

If you only want to add a custom column, just click Custom Column in Power Query.

vkalyjmsft_3-1666690325972.png

Then put in this code:

if Text.Contains([Source],"(") then Text.BetweenDelimiters([Source], "(", ")") else [Source]

Certainly, maybe you should modify the table/column names according to your sample.

 

Best Regards,
Community Support Team _ kalyj

ryan_mayu
Super User
Super User

@WtP 

Here is a workaround for you.

create a column from example

1.PNG

then you type in the expected output one by one, it will automatically help you extract the data. You need to modify the one that does not display the expected output.

2.PNG





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

Proud to be a Super User!




Hi @ryan_mayu 

 

The other solution solved it. I just wanted to point out that I also tried your solution and this works realy well also. I am sure I'll be using this option a lot in the future because I think it is very flexible, so thank you for your reply!

 

Kind regards.

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.