This examples illustrates how you can convert IP addresses to numeric values for purposes of comparison and sorting. This example illustrates the following functions:

  • IPTOINT - converts an IP address to an integer value according to a formula. See IPTOINT Function.
  • IPFROMINT - converts an integer value back to an IP address according to formula. See IPFROMINT Function.


Your dataset includes the following values for IP addresses:



When the above data is imported, the application initially types the column as URL values, due to the presence of the http:// and https:// protocol identifiers. Select the IP Address data type for the column. The last three values are listed as mismatched values. You can fix the issues with the last two entries by applying the following transform, which matches on both http:// and https:// strings:

replace col:IpAddr with:'' on:`http%?://`

NOTE: The %? Cloud Dataprep pattern matches zero or one time on any character, which enables the matching on both variants of the protocol identifier.

Now, only the 1.2.3 value is mismatched. Perhaps you know that there is a missing zero at the end of it. To add it back, you can do the following:

replace col: IpAddr on: `1.2.3{end}` with: '' global: true

All values in the column should be valid for the IP Address data type. To convert these values to their integer equivalents:

derive value:IPTOINT(IpAddr) as:'ip_as_int'

You can now manipulate the data based on this numeric key. To convert the integer values back to IP addresses for checking purposes, use the following:

derive value:IPFROMINT(ip_as_int) as:'ip_check'


Was this page helpful? Let us know how we did:

Send feedback about...

Google Cloud Dataprep Documentation