Forum Discussion

leebaldwin's avatar
leebaldwin
Helper I
3 years ago
Solved

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. 

  • ryan_mayu's avatar
    ryan_mayu
    3 years ago

    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

7 Replies

  • Stachu's avatar
    Stachu
    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

     

  • 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's avatar
        leebaldwin
        Helper I

        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.