Forum Discussion

bashheadonwall's avatar
bashheadonwall
New Member
4 years ago
Solved

How do I create a custom column that grabs the ip from a description?

I'm trying to make a simple dashboard to review our logs and was hoping I could create  custom column that grabs IP addresses from the description but I am having a rough time when there is no IP or if its not in between two lines.

 

Is there a way for powerbi to look for #.#.#.# which is typically an IP address and display it in a column and not show anything if there isn't an IP #.#.#.# in the description? 

 

  • Hi bashheadonwall ,

    Use the following dax to create a new column:

     

    Column = 
    VAR test1 =
        MID ( 'Table'[Description], SEARCH ( ":", 'Table'[Description],, 0 ) + 1, 1 )
    VAR test2 =
        SEARCH (
            ",",
            'Table'[Description],
            SEARCH ( ":", 'Table'[Description],, 0 ) + 1,
            0
        )
    VAR test3 =
        IF (
            test1 = "1"
                || test1 = "2"
                || test1 = "3"
                || test1 = "4"
                || test1 = "5"
                || test1 = "6"
                || test1 = "7"
                || test1 = "8"
                || test1 = "9"
                || test1 = "0",
            MID (
                'Table'[Description],
                SEARCH ( ":", 'Table'[Description],, 0 ) + 1,
                test2
                    - ( SEARCH ( ":", 'Table'[Description],, 0 ) + 1 )
            )
        )
    RETURN
        test3
    

     

     

    return:

     

     

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


    Best Regards

    Lucien

2 Replies

  • Hi,

    Have you tried using the Column from Examples feature of the Query Editor?

  • v-luwang-msft's avatar
    v-luwang-msft
    Icon for Community Support rankCommunity Support

    Hi bashheadonwall ,

    Use the following dax to create a new column:

     

    Column = 
    VAR test1 =
        MID ( 'Table'[Description], SEARCH ( ":", 'Table'[Description],, 0 ) + 1, 1 )
    VAR test2 =
        SEARCH (
            ",",
            'Table'[Description],
            SEARCH ( ":", 'Table'[Description],, 0 ) + 1,
            0
        )
    VAR test3 =
        IF (
            test1 = "1"
                || test1 = "2"
                || test1 = "3"
                || test1 = "4"
                || test1 = "5"
                || test1 = "6"
                || test1 = "7"
                || test1 = "8"
                || test1 = "9"
                || test1 = "0",
            MID (
                'Table'[Description],
                SEARCH ( ":", 'Table'[Description],, 0 ) + 1,
                test2
                    - ( SEARCH ( ":", 'Table'[Description],, 0 ) + 1 )
            )
        )
    RETURN
        test3
    

     

     

    return:

     

     

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


    Best Regards

    Lucien