Forum Discussion
IP address mapping
- 9 years ago
Hi reno1
You can do it with the following steps below.
You need to create a function with the following code below with the name of fn_GetIPAddress
let Source = (#"IP Address" as text) => let Source = Json.Document(Web.Contents("http://freegeoip.net/json/" & #"IP Address")), #"Converted to Table" = Record.ToTable(Source), #"Transposed Table" = Table.Transpose(#"Converted to Table"), #"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table") in #"Promoted Headers" in SourceThe function will return the output into a table.
Then what you do is where your data is in the Query Editor you click on Invoke Custom Function, then put in the required fields as shown below.
NOTE: Make sure to select your column above that has got the IP Addresses
Then once you click Ok you will see the table as shown below.
Click on the Expand Table button, leave all the defaults and click Ok.
You should then get the details for each IP Address.
NOTE: There are more columns but I snipped them off.
Please let me know if this works or you get stuck.
Hi reno1
You can do it with the following steps below.
You need to create a function with the following code below with the name of fn_GetIPAddress
let
Source = (#"IP Address" as text) => let
Source = Json.Document(Web.Contents("http://freegeoip.net/json/" & #"IP Address")),
#"Converted to Table" = Record.ToTable(Source),
#"Transposed Table" = Table.Transpose(#"Converted to Table"),
#"Promoted Headers" = Table.PromoteHeaders(#"Transposed Table")
in
#"Promoted Headers"
in
SourceThe function will return the output into a table.
Then what you do is where your data is in the Query Editor you click on Invoke Custom Function, then put in the required fields as shown below.
NOTE: Make sure to select your column above that has got the IP Addresses
Then once you click Ok you will see the table as shown below.
Click on the Expand Table button, leave all the defaults and click Ok.
You should then get the details for each IP Address.
NOTE: There are more columns but I snipped them off.
Please let me know if this works or you get stuck.
GilbertQ, thanks for the detailed answer! Really helpful.
I cant seem to get it to work for me though.
Firstly I go into the query editor, right click on the table containing the IPs, and select "Create Function....". Then I get this error message:
Then I go 'Create' > Enter the name of the function > Paste the code into the box > Continued with this
NOTE: My table is called 'LocationTest'.
I then go to where my data is in the query editor and try to invoke custom function. In this dialogue, I cannot select anything for 'Function Query':
Have I done something wrong here? I have a feeling that I'm not creating the custom function correctly.
Thanks again for all your help.
- GilbertQ9 years agoSuper User
Hi reno1
The first step that you need to do, is to create a Blank Query.
Then go into the Advanced Editor for the Blank Query you just created.
Once in the Advanced Editor the copy and paste the code.
Once done you should see the function with the option to put in the value