Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
paulineCom
Helper I
Helper I

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" with the value that the USERNAME() function is sending.

But in order to do that, i need to create a dimention table of user like this :

 

user id ; user name (that refers to mu "name_user" ; the result of the USERNAME() function.

I will fill up the table because i know what is the username() of the different "name_user"

And then i'll be abble to create roles to filter my table in function of their username.

 

So my question is : how do I create a table just with 3 columns ? I've tried to follow the documentation but there is always some errors in my code. Maybe an exemple would help me a lot.

 

Many thanks.

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

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"; "A@gmail.com"; "Role"; "Manager" );
    ROW ( "Name"; "B"; "E-mail"; "B@gmail.com"; "Role"; "Worker" );
    ROW ( "Name"; "C"; "E-mail"; "C@gmail.com"; "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.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

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"; "A@gmail.com"; "Role"; "Manager" );
    ROW ( "Name"; "B"; "E-mail"; "B@gmail.com"; "Role"; "Worker" );
    ROW ( "Name"; "C"; "E-mail"; "C@gmail.com"; "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.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hello thank you both for your help,

 

It's working thanks to the syntax @MFelix  gave me.

 

Have a nice day 🙂

Pragati11
Super User
Super User

Hi @paulineCom ,

 

Did you try selecting just 3 columns from your main table and creating your table?

 

You can do this easily in Query editor in Power BI.

  1. Richt click on your base table -> select REFERENCE (this creates a new table)
  2. select the columns you want in this table and delete others.
  3. Remove duplicate rows from your USER column.
  4. Create a relationship as required.

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.