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
Anonymous
Not applicable

Create a Calculated Column from Different Tables

Hi,

 

I have two table (alot more but ill use two).

 

In my ad details table 'addetails' I have a column called 'adqinstr' in there I have mulitple rows with either "Private", "Trade", or "Bus Acc".

In my customer table 'custAcc'  I have created a cacluated column where i want to say if find "Buss  Acc" then set it to "BA" else put "normal".

 

None of the DAX functions seem to be available (no list appears) and the useful columns only seem to show the columns for that table.

 

Thanks

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

@Anonymous

 

According to the table relationship shortcut you provided above, there is a One to Many relationship between table "custAcc" ant table "adDetails", and table "custAcc" is on the one side of the relationship. In this scenario, you should use RELATEDTABLE function to create the calculated column for table "custAcc".

 

The formula below is for your reference.

Column =
IF (
    CONTAINS ( RELATEDTABLE ( adDetails ), adDetails[adqinstr], "Bus Acc" ),
    "BA",
    "Normal"
)

 Regards

View solution in original post

13 REPLIES 13
v-ljerr-msft
Employee
Employee

@Anonymous

 

According to the table relationship shortcut you provided above, there is a One to Many relationship between table "custAcc" ant table "adDetails", and table "custAcc" is on the one side of the relationship. In this scenario, you should use RELATEDTABLE function to create the calculated column for table "custAcc".

 

The formula below is for your reference.

Column =
IF (
    CONTAINS ( RELATEDTABLE ( adDetails ), adDetails[adqinstr], "Bus Acc" ),
    "BA",
    "Normal"
)

 Regards

BhaveshPatel
Community Champion
Community Champion

Hi There,

 

You can create the conditional column in Query mode.

 

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
Anonymous
Not applicable

Hi Bhavesh,

 

I have tried but it does not seem to give me the option to reference the other table.

 

Thanks

Anonymous
Not applicable

Sort of like 

 

 

Column = If(Related('adDetails'[adqinstr])="Bus Acc","BA","Normal")

But it doesnt work

Can you please share your data model?

 

Thanks

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Hi There,

 

Instead of relying on calculated column, why don't you try merging both the tables and It can give you desire results.

 

Thanks & Regards,

Bhavesh

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.
Anonymous
Not applicable

Hi Pacesh I wanting to keep them seperate to maintain integrity,

 

Please find attached my data model

 

DataMdel.JPG

wonga
Continued Contributor
Continued Contributor

@Anonymous

 

Since your data model appears to have relationships all over, can't you instead use DAX to make your calculated column instead of Power Query (M)?

 

To make a DAX calculated column right click the table you want to create the column in and click "New Calculated Column"

Anonymous
Not applicable

Hi Wonga,

 

Ive tried to use 

 

Column = If(Related('adDetails'[adqinstr])="Bus Acc","BA","Normal")

But it does not seem to like it ....struggling with the DAX.

 

 

Thanks

wonga
Continued Contributor
Continued Contributor

@Anonymous When you say it doesn't seem to like it, can you expand on that? What is the exact error message?

Anonymous
Not applicable

The column 'adDetails[adqinstr]' either doesn't exist or doesn't have a relationship to any table available in the current context.

Anonymous
Not applicable

The column 'adDetails[adqinstr]' either doesn't exist or doesn't have a relationship to any table available in the current context.

Anonymous
Not applicable

The column 'adDetails[adqinstr]' either doesn't exist or doesn't have a relationship to any table available in the current context.

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