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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
tragonneau
Frequent Visitor

Related table - Calculated column

Hello,

 

I use DirectQuery.

I am working with two tables, let's say Table1 and Table2 for exemple :

Table1.pngTable2.png

 

The relation between these 2 tables is : Table2[id] (many)=>(one) Table1[id]

 

I wanted to create a calculated column like this :

CalculatedColumn = IF(RELATED(Table1[deal_type]) = "Sell";Table2[sell_destination];Table2[buy_destination])

 

To have a result like this :

Table2WithNewColumn.png

 

But it seems I can't use RELATED in calculated columns in DirectQuery.

 

Also, using RELATED in measures causes me this error : 'The column xxx either doesn't exist or doesn't have a relationship to any table available in the current context'. 

 

I feel a bit lost because I think this problem is easy to solve but I can't find a way to do it...

I would be happy to have some help. 

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @tragonneau,

 

I also verified that we may not be able to use RELATED function to create calculate columns in Direct Query mode currently. However, you should be able to use RELATED function to create a measure in Direct Query mode in your scenario. 

 

As the RELATED function requires a row context to work correctly, you need to create a row context inside a DAX expression by using iterators(SUMX, FILTER etc.). The formula below is for your reference.Smiley Happy

Measure = 
IF (
    HASONEVALUE ( Table2[id] ),
    IF (
        CALCULATE (
            COUNTROWS ( Table2 ) = 1,
            FILTER ( Table2, RELATED ( Table1[deal_type] ) = "Sell" )
        ),
        VALUES ( Table2[sell_destination] ),
        VALUES ( Table2[buy_destination] )
    )
)

 

Regards

View solution in original post

1 REPLY 1
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @tragonneau,

 

I also verified that we may not be able to use RELATED function to create calculate columns in Direct Query mode currently. However, you should be able to use RELATED function to create a measure in Direct Query mode in your scenario. 

 

As the RELATED function requires a row context to work correctly, you need to create a row context inside a DAX expression by using iterators(SUMX, FILTER etc.). The formula below is for your reference.Smiley Happy

Measure = 
IF (
    HASONEVALUE ( Table2[id] ),
    IF (
        CALCULATE (
            COUNTROWS ( Table2 ) = 1,
            FILTER ( Table2, RELATED ( Table1[deal_type] ) = "Sell" )
        ),
        VALUES ( Table2[sell_destination] ),
        VALUES ( Table2[buy_destination] )
    )
)

 

Regards

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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