Forum Discussion

bmcirillo's avatar
bmcirillo
Regular Visitor
6 years ago
Solved

Transform Table of Multiple Columns to Single Column

I am new to DAX and need some help figuring out the proper formula and syntax for a table transformation, which I can hopefully explain in a way that makes sense...

 

I have Table X with Unique IDs and several True/False columns, and in order to get the visualizations in the way I want, need to be able to transform the table so that instead there is a new combined column where every True value from the original table is instead populates the name of that original column name.

 

So the original table is formatted like this:

IDABC
1TRUEFALSETRUE
2FALSEFALSETRUE
3TRUEFALSEFALSE
4TRUETRUEFALSE
5TRUETRUEFALSE
6FALSEFALSETRUE
7FALSETRUETRUE

 

and would like to be able to create a new table so that it instead looks like this:

IDCOMBINED
1A
1C
2C
3A
4A
4B
5A
5B
6C
7B
7C

 

I've played around with unpivoting the columns and then trying to create a formula based on the new unpivoted columns, but I haven't been able to find the right functions to make this happen, but can't help but think it's entirely possible and probably not even especially complicated...

 

any help is appreciated, thanks!

  • HI  bmcirillo 

    There are two way to for you refer to:

    1. Duplicate a table in edit queries, then unpivot the Column A,B,C , filter out false and remove this column.

     

    2. Use Union to create a new calculate table 

    New table = 
    UNION(SELECTCOLUMNS(FILTER('Table','Table'[A]=TRUE()),"ID",[ID],"COMBINED","A"),
          SELECTCOLUMNS(FILTER('Table','Table'[B]=TRUE()),"ID",[ID],"COMBINED","B"),
          SELECTCOLUMNS(FILTER('Table','Table'[C]=TRUE()),"ID",[ID],"COMBINED","C")
         )

    Result:

     

    and here is sample pbix file,please try it.

     

    Regards,

    Lin

2 Replies

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

    HI  bmcirillo 

    There are two way to for you refer to:

    1. Duplicate a table in edit queries, then unpivot the Column A,B,C , filter out false and remove this column.

     

    2. Use Union to create a new calculate table 

    New table = 
    UNION(SELECTCOLUMNS(FILTER('Table','Table'[A]=TRUE()),"ID",[ID],"COMBINED","A"),
          SELECTCOLUMNS(FILTER('Table','Table'[B]=TRUE()),"ID",[ID],"COMBINED","B"),
          SELECTCOLUMNS(FILTER('Table','Table'[C]=TRUE()),"ID",[ID],"COMBINED","C")
         )

    Result:

     

    and here is sample pbix file,please try it.

     

    Regards,

    Lin

    • bmcirillo's avatar
      bmcirillo
      Regular Visitor

      Thank you, I knew it wasn't that complicated! For some reason, when I was playing around with it I wasn't even thinking about unpivoting all of the columns in one go...I assumed I had to do each one individually and that's where I was running into issues.