Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Create new column. Current column has values separated by a semicolon and hashtag

I current have a column called Program. The values are separate by a semicoln and hashtag. The first table below is a mock up of the data and the 2nd table is my desired result.  In the actual data t...
  • Jihwan_Kim's avatar
    3 years ago

    Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new table.

     

     

     

    Desired table = 
    VAR _newtable =
        ADDCOLUMNS ( Data, "@new", SUBSTITUTE ( Data[Program], ";#", "|" ) )
    VAR _separate =
        ADDCOLUMNS (
            _newtable,
            "@first", PATHITEM ( [@new], 1 ),
            "@second", PATHITEM ( [@new], 2 ),
            "@third", PATHITEM ( [@new], 3 ),
            "@fourth", PATHITEM ( [@new], 4 )
        )
    VAR _finaltable =
        UNION (
            SUMMARIZE ( _separate, [@first], Data[Count] ),
            SUMMARIZE ( _separate, [@second], Data[Count] ),
            SUMMARIZE ( _separate, [@third], Data[Count] ),
            SUMMARIZE ( _separate, [@fourth], Data[Count] )
        )
    RETURN
        GROUPBY (
            FILTER (
                SELECTCOLUMNS (
                    _finaltable,
                    "@Program unique", [@first],
                    "@Count", Data[Count]
                ),
                [@Program unique] <> BLANK ()
            ),
            [@Program unique],
            "Count", SUMX ( CURRENTGROUP (), [@Count] )
        )