cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

## Related table - Calculated column

Hello,

I use DirectQuery.

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

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

I wanted to create a calculated column like this :

To have a result like this :

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
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.

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

Regards

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.

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

Regards

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors