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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DeoYadav
Regular Visitor

Calculated table using DAX

How to get the result as below.

 

EMP_table

DeoYadav_0-1660160157831.png  

 

Department_table

DeoYadav_1-1660160261067.png

 

Result Table

EmpIdNameDepName
1RajIT
2KishorHR
2AbhiFR
4KiranNo Department

 

May be I'm missing the result in this example.

 

1 ACCEPTED SOLUTION

Hi @DeoYadav,

 

I use selectedcolumns() to do this.

 

Result Table =
SELECTCOLUMNS (
    'EMP_table',
    "empid", [new EmpID],
    "name", [Name],
    "DepName",
        IF (
            ISBLANK ( RELATED ( Department_table[DepName] ) ),
            "No Department",
            RELATED ( Department_table[DepName] )
        )
)

 

 

Result:

vchenwuzmsft_0-1660703126481.png

 


Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-chenwuz-msft
Community Support
Community Support

Hi @DeoYadav ,

 

Can you explain why the second and third rows are the same Empid 2?

 

If you want get the depName from Department_table, a relationship between these two tables on DepID is needed. Then create the new column in EMP_table via related(Department_table[DepName])

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Anonymous
Not applicable

Hi @v-chenwuz-msft , "Can you explain why the second and third rows are the same Empid 2?" - this is the result that I want in a calculated table.

 

Hi @DeoYadav,

 

I use selectedcolumns() to do this.

 

Result Table =
SELECTCOLUMNS (
    'EMP_table',
    "empid", [new EmpID],
    "name", [Name],
    "DepName",
        IF (
            ISBLANK ( RELATED ( Department_table[DepName] ) ),
            "No Department",
            RELATED ( Department_table[DepName] )
        )
)

 

 

Result:

vchenwuzmsft_0-1660703126481.png

 


Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ValtteriN
Super User
Super User

Hi,

Your department table had a duplicate id. I will ignore it in my example.

Here is one way to do this:

Table 6 = ADDCOLUMNS(EMP_table,"Department",RELATED(Department_table[DepName]))

ValtteriN_0-1660163810361.png

 


If you want to differentiate between HR and FR the depID's should be unique.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/




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

Proud to be a Super User!




Anonymous
Not applicable

Hi @ValtteriN  tables can have multiple ids where we use M:M relationship in our model, correct? so what would be result in the case of M:M, can we get the result as shown in the result table?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors