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
leebaldwin
Frequent Visitor

If/Else For 2 Tables

First, I have to say, this user community is AWESOME! Everyone is so professional in the way they handle questions and responses that I do not see in other user groups.

 

Now, I have a report I am building that has a query pulling information from our IBM DB2 system and a table that I created. Each of these have a PALLET_LOC field. I have a relationship between these based on the PALLET_LOC field and the table has a LocationTag field (value: Exclude) that gets returned to my report. My issue is that if the PALLET_LOC is in the exclude table, then is putting Exclude out in the report, but I need to have it output Include if the PALLET_LOC is not in the table. I am used to other languages if/else statements to do this, but PB is causing me issues. I know I could do a Conditional Column and have each location in the if/else statement, but it would be easier to maintain if I had only had to add a value to the table to update the report. 

1 ACCEPTED SOLUTION

@leebaldwin 

if the relationship between warehouse table and location table is many to one

you can try this

Column = if( RELATED(PalletLocation[LOC_TAG])="","Include",RELATED(PalletLocation[PALLET_LOC]))

pls see the attachment below





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

Proud to be a Super User!




View solution in original post

7 REPLIES 7
leebaldwin
Frequent Visitor

@Stachu Thank you. I wasn't sure what information you might need. Here are the 2 tables in question. I am doing a one-to-many relationship on these.

 

qryWarehousePallet

ORD_NUMSKUPALLET_LOCLOC_TAG
246ABC9Q6PLTEXCLUDE
998EEDH107AINCLUDE

 

tblPalletLocation

PALLET_LOCLOC_TAG
Q6PLTExclude
LOCQ6Exclude
Q601AExclude
FLOORExclude
MIA01Exclude

@leebaldwin 

what's the expected output based on your sample data?





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

Proud to be a Super User!




Based on the sample data, if qryWarehousePallet.PALLET_LOC is in tblPalletLocation.PALLET_LOC, then it returns tblPalletLocation.LOC_TAG, which would be Exclude, else it returns the word Include. 

@leebaldwin 

if the relationship between warehouse table and location table is many to one

you can try this

Column = if( RELATED(PalletLocation[LOC_TAG])="","Include",RELATED(PalletLocation[PALLET_LOC]))

pls see the attachment below





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

Proud to be a Super User!




Thanks @ryan_mayu that worked perfectly.

you are welcome





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

Proud to be a Super User!




Stachu
Community Champion
Community Champion

Can you add sample tables (in format that can be copied to PowerBI) from your model with anonymised data? Like this (just copy and paste into the post window).

Column1Column2
A1
B2.5

 



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.