Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Create new column based on text from a messy text blob

So, I have a column with data that looks like this: #Research; #ourResearch-Cat1-Subcat1; #Benchmark; 2018; Benchmark #Research; #OurResearch-Cat1-Subcat2; #Benchmark; Benchmark #OURRES...
  • Phil_Seamark's avatar
    Phil_Seamark
    7 years ago

    Hi Anonymous

     

    Please try these two calculated columns as an alternative.  These are in DAX and again, I have attached a PBIX file that you can download to see/tweak etc.

     

    Category = 
    VAR LengthOfText = LEN('Table1'[Column1])
    VAR StartingPointOR = SEARCH("#OurResearch",'Table1'[Column1],1,0)+1
    VAR RestOfText1 =  MID('Table1'[Column1],StartingPointOR+12,LengthOfText-StartingPointOR+1) & ";"
    VAR StartingPointSC = SEARCH(";",RestOfText1,1,0)-1
    VAR RestOfText2 = LEFT(RestOfText1,StartingPointSC)
    VAR StartingPointDash = SEARCH("-",RestOfText2,1,0)
    
    RETURN 
        IF(
            StartingPointDash>0,
            LEFT(RestOfText2,StartingPointDash-1),
            RestOfText2
            )

    and

     

    Sub Category = 
    VAR LengthOfText = LEN('Table1'[Column1])
    VAR StartingPointOR = SEARCH("#OurResearch",'Table1'[Column1],1,0)+1
    VAR RestOfText1 =  MID('Table1'[Column1],StartingPointOR+12,LengthOfText-StartingPointOR+1) & ";"
    VAR StartingPointSC = SEARCH(";",RestOfText1,1,0)-1
    VAR RestOfText2 = LEFT(RestOfText1,StartingPointSC)
    VAR StartingPointDash = SEARCH("-",RestOfText2,1,0)
    
    RETURN 
        IF(
            StartingPointDash>0,
            MID(RestOfText2,StartingPointDash+1,99)
            )