Forum Discussion

Danny26's avatar
Danny26
Frequent Visitor
9 years ago
Solved

How to split Azure resource tags in to separate columns.

Hi All, After much research and trial and error I am trying to figure out a way to parse the Azure resource tags that are exported using the Azure Enterprise connector and use them against other m...
  • Danny26's avatar
    Danny26
    9 years ago

    Hi v-ljerr-msft

     

    Sorry for the multiple posts but I think I have had some success. The code below which includes an IF statement at the start does seem to do the trick and doesn't error out when it can not find the key word. It may not be pretty but it seems to do the job, if you could offer any further refinements that would be great but otherwise I think we might have cracked it. 

     

    Hostname = 
    IF(SEARCH( "Hostname" ,'Table1-Full'[Tags],,BLANK() ) ,(
    VAR textLength =
        SEARCH (
            ",",
            'Table1-Full'[Tags],
            SEARCH ( "Hostname", 'Table1-Full'[Tags] ) + LEN ( "Hostname" )
                + 3
        )
            - (
                SEARCH ( "Hostname", 'Table1-Full'[Tags] ) + LEN ( "Hostname" )
                    + 3
            )
            - 1
    RETURN
        MID (
            'Table1-Full'[Tags],
            SEARCH ( "Hostname", 'Table1-Full'[Tags] ) + LEN ( "Hostname" )
                + 3,
            textLength
        )))

     

    Thanks

    Danny

  • Danny26's avatar
    Danny26
    9 years ago

    Hi v-ljerr-msft

     

    Thank you for your help with developing this solution. I have updated the code slightly to cater for the fact that when a particular Tag I am searching for is at the end of the text string the code would fail because it can't find the last delimitated character ",". So I have changed the delimited character to be ". Now any tag of any length and position within the string can be found and separated out into its own column. e.g. Workload, Location, Hostname. Hopefully this code can be used by others who are trying to report against Azure resource tags. 

     

    Hostname = 
    IF(SEARCH( "Hostname" ,'All-Azure-Data'[Data.Tags],,BLANK() ) ,(
    VAR textLength =
        SEARCH (
            """",
            'All-Azure-Data'[Data.Tags],
            SEARCH ( "Hostname", 'All-Azure-Data'[Data.Tags] ) + LEN ( "Hostname" )
                + 3
        )
            - (
                SEARCH ( "Hostname", 'All-Azure-Data'[Data.Tags] ) + LEN ( "Hostname" )
                    + 3
            )
            
    RETURN
        MID (
            'All-Azure-Data'[Data.Tags],
            SEARCH ( "Hostname", 'All-Azure-Data'[Data.Tags] ) + LEN ( "Hostname" )
                + 3,
            textLength
        )))