Forum Discussion

paulineCom's avatar
paulineCom
Helper I
5 years ago
Solved

How can I create a user table with dax ?

Hello,   Here is my problem : I have a huge table in direct query with a column named "name_user" it contain a dozen of differents users.    I want to create role that match their "name_user" wit...
  • MFelix's avatar
    5 years ago

    Hi paulineCom ,

     

    Can you give a little bit more information please? What is the syntax you are using and the information you want to place in the table.

     

    To creata a table in dax you have several options but this depends on the way you want to build you can do:

    Table2 =
    ADDCOLUMNS (
        DISTINCT ( 'Table'[Name] );
        "E-mail"; 'Table'[Name] & "@gmail.com";
        "Role"; SWITCH ( 'Table'[Name]; "A"; "MANAGER"; "WORKER" )
    )

    This table uses the distinct values of Name column in another tables and add two additional tables one with e-mail and another with role based no the name of the person

     

    You can also create a table with a single column:

    Table2 = DISTINCT ( 'Table'[Name] )

    And the add each individual column:

    E-mail = 'Table2'[Name] & "@gmail.com"
    
    Role = SWITCH ( 'Table2'[Name]; "A"; "MANAGER"; "WORKER" )
    

     

    You can create a table with all values written direcftly in the code:

    Table 3 =
    UNION (
        ROW ( "Name"; "A"; "E-mail"; "[email protected]"; "Role"; "Manager" );
        ROW ( "Name"; "B"; "E-mail"; "[email protected]"; "Role"; "Worker" );
        ROW ( "Name"; "C"; "E-mail"; "[email protected]"; "Role"; "Worker" )
    )

     

    There is a various number of ways to build this, I know I have been very generic but without any sample data is difficult to pin point what is happening in your model.