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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Mburman-07
Helper I
Helper I

Replace category with Category from another table

Hi All,

I have two tables WIND_FAULT_CATEGORIES_GADS and WIND_FAULT_CATEGORIES_IEC. They both have a relationship to my events table using 1 to many. The WIND_FAULT_CATEGORIES_GADS joins to events on GADS Code and the IEC table joins on IEC code.

I'm trying to build a measure or column that will allow me to show the following:

If WIND_FAULT_CATEGORIES_GADS System = "Wind Turbine" then return the WIND_FAULT_CATEGORIES_IEC Category else give me the GADS System.

In SQL it would be a simple IF statement or a CASE statement but I can't figure out how to replicate this in PBI

Thanks in advance,

Mike

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @Mburman-07 ,

 

I treid to create some dummy data for reference.

The relationship:

vstephenmsft_0-1734938668895.png

WIND_FAULT_CATEGORIES_GADS:

vstephenmsft_6-1734941589181.png

 

WIND_FAULT_CATEGORIES_IEC:

vstephenmsft_7-1734941595757.png

The scenario on my side is that I want to check which shops my fruits or vegetables are sold in the GADS table.

If my sample data above is similar with yours, let's move on.

You can't use RELATED function in table GADS but you can use the RELATED in table IEC because of the relationship. In table GADS, a GADS code will have multiple IEC codes associated with it, which causes an error that if you use the RELATED function in table GADS , you cannot return a single value.

vstephenmsft_3-1734938998958.png

This is a reproduction of the issue.

vstephenmsft_8-1734941745115.png

 

 

To solve this, we can merge tables in Power Query.

Merge the Tables:

In Power BI Desktop, go to the Home tab and click on Merge Queries.
Select the Products table as the first table and the Categories table as the second table.
Merge them using the matching columns.

vstephenmsft_9-1734941773006.png

 


Expand the Merged Table:

After merging, you will see a new column with a table icon. Click on the expand icon (two arrows) next to this column.
Select Shops column and click OK.

vstephenmsft_11-1734941820533.png

vstephenmsft_12-1734941826431.png

At this time, you are very close to success, and you will get an error below when you close and apply, which is good to delete this relationship and it will be loaded successfully.

vstephenmsft_13-1734941912673.png

 

If you want DAX instead of the transformation in Power Query. You can create a calculated table with DAX to implement it.

Table = FILTER(CROSSJOIN('WIND_FAULT_CATEGORIES_GADS','WIND_FAULT_CATEGORIES_IEC'),[GADS Code]=[IEC code])

With such a calculation table, the result can be obtained.

vstephenmsft_14-1734942235926.png

The easiest way I think is just drag the fields from tables, and it will show the result because of your relationship connected.

vstephenmsft_15-1734942373636.png

 

 

Best Regards,

Stephen Tao

 

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

11 REPLIES 11
v-stephen-msft
Community Support
Community Support

Hi @Mburman-07 ,

 

I treid to create some dummy data for reference.

The relationship:

vstephenmsft_0-1734938668895.png

WIND_FAULT_CATEGORIES_GADS:

vstephenmsft_6-1734941589181.png

 

WIND_FAULT_CATEGORIES_IEC:

vstephenmsft_7-1734941595757.png

The scenario on my side is that I want to check which shops my fruits or vegetables are sold in the GADS table.

If my sample data above is similar with yours, let's move on.

You can't use RELATED function in table GADS but you can use the RELATED in table IEC because of the relationship. In table GADS, a GADS code will have multiple IEC codes associated with it, which causes an error that if you use the RELATED function in table GADS , you cannot return a single value.

vstephenmsft_3-1734938998958.png

This is a reproduction of the issue.

vstephenmsft_8-1734941745115.png

 

 

To solve this, we can merge tables in Power Query.

Merge the Tables:

In Power BI Desktop, go to the Home tab and click on Merge Queries.
Select the Products table as the first table and the Categories table as the second table.
Merge them using the matching columns.

vstephenmsft_9-1734941773006.png

 


Expand the Merged Table:

After merging, you will see a new column with a table icon. Click on the expand icon (two arrows) next to this column.
Select Shops column and click OK.

vstephenmsft_11-1734941820533.png

vstephenmsft_12-1734941826431.png

At this time, you are very close to success, and you will get an error below when you close and apply, which is good to delete this relationship and it will be loaded successfully.

vstephenmsft_13-1734941912673.png

 

If you want DAX instead of the transformation in Power Query. You can create a calculated table with DAX to implement it.

Table = FILTER(CROSSJOIN('WIND_FAULT_CATEGORIES_GADS','WIND_FAULT_CATEGORIES_IEC'),[GADS Code]=[IEC code])

With such a calculation table, the result can be obtained.

vstephenmsft_14-1734942235926.png

The easiest way I think is just drag the fields from tables, and it will show the result because of your relationship connected.

vstephenmsft_15-1734942373636.png

 

 

Best Regards,

Stephen Tao

 

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

 

 

Bibiano_Geraldo
Super User
Super User

Hi @Mburman-07 ,

Option 1: Using a Calculated Column:

Result = 
IF (
    RELATED(WIND_FAULT_CATEGORIES_GADS[System]) = "Wind Turbine",
    RELATED(WIND_FAULT_CATEGORIES_IEC[Category]),
    RELATED(WIND_FAULT_CATEGORIES_GADS[System])
)

 

Option 2: Using a Measure:

Result Measure = 
IF (
    SELECTEDVALUE(WIND_FAULT_CATEGORIES_GADS[System]) = "Wind Turbine",
    SELECTEDVALUE(WIND_FAULT_CATEGORIES_IEC[Category]),
    SELECTEDVALUE(WIND_FAULT_CATEGORIES_GADS[System])
)
Kedar_Pande
Super User
Super User

@Mburman-07 

Calculated Column

FaultCategory = 
IF (
RELATED(WIND_FAULT_CATEGORIES_GADS[System]) = "Wind Turbine",
RELATED(WIND_FAULT_CATEGORIES_IEC[Category]),
RELATED(WIND_FAULT_CATEGORIES_GADS[System])
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

danextian
Super User
Super User

Try

VAR _GADS =
    LOOKUPVALUE (
        WIND_FAULT_CATEGORIES_GADS[System],
        WIND_FAULT_CATEGORIES_GADS[event id], WIND_FAULT_CATEGORIES_IEC[event id]
    )
RETURN
    IF (
        _GADS = "Wind Turbine",
        WIND_FAULT_CATEGORIES_IEC[Category],
        WIND_FAULT_CATEGORIES_GADS[System]
    )

 

If this returns an error stating that a single value cannot be determined, it means that the result is more than one, an event id in WIND_FAULT_CATEGORIES_IEC returns more than one WIND_FAULT_CATEGORIES_GADS[System]. In this case, which among the values to pick?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian 

Thank you for this, unfortunately this wouldn't work as each table has unique Event ID. In fact they don't share any common columns. The GADS table joins to events on Gads_Code = Gads_Event_Code and IEC joins on IEC_Code = IEC_Events_Code

Can you please a workable sample data (not an image), your expected result from that and the reasoning behind. We've been trying to hit at something without properly aiming at it.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
anmolmalviya05
Super User
Super User

Hi @Mburman-07 , Please try to create below calculated column:

CombinedCategory =
IF(
RELATED(WIND_FAULT_CATEGORIES_GADS[System]) = "Wind Turbine",
RELATED(WIND_FAULT_CATEGORIES_IEC[Category]),
RELATED(WIND_FAULT_CATEGORIES_GADS[System])
)

Hi @anmolmalviya05 

I tried this solution however the RELATED function expects just  a column name and this returns an error

"The column WIND_FAULTS_CATEGORIES_GADS[System] either doesn't exist or doesnt have a relationship to any table availablie in the current context.

Uzi2019
Super User
Super User

Hi @Mburman-07 

 

Create this Calculated Column:

 

Column = IF ( 'Table1'[System]= "Wind Turbine", Related('Table2'[Category]), 'Table1'[System])

 

 

 

I hope I answered your question!

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Hi @Uzi2019 

I have tried this solution and returned an error in the measure,

"A single value for column 'System' in thable R_WIND_FAULT_CATEGORIES_GADS cannot be determined.

ryan_mayu
Super User
Super User

you can try to use RELATED get the data from another table.

 

https://learn.microsoft.com/en-us/dax/related-function-dax?wt.mc_id=DP-MVP-5004616

 

if this does not work, pls provide some sample data and expected output





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

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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