Forum Discussion

vanonyuo's avatar
vanonyuo
Frequent Visitor
6 years ago
Solved

Conditional lookup values from multiple columns in related/lookup table.

Hello,   I am trying to find the best way to look up values in Table 2 from multiple columns And successfull getting different errors   Example of what I am trying to accomplish: If ('table1'[nu...
  • v-alq-msft's avatar
    6 years ago

    Hi, vanonyuo 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

     

    Table1:

     

    Table2:

     

    There is a relationship between two tables. You may create a calculated column or a measure as below.

    Calculated column:
    Column = 
    IF(
        Table1[Number]>0&&Table1[Number]<4,
        RELATED(Table2[Column1]),
        IF(
            Table1[Number]>=4&&Table1[Number]<=7,
            RELATED(Table2[Column2]),
            IF(
                Table1[Number]>7,
                RELATED(Table2[Column3])
            )
        )
    )
    
    Measure:
    Measure = 
    var tab = 
    ADDCOLUMNS(
        Table1,
        "Result",
        var _number = [Number]
        return
        IF(
            _number>0&&_number<4,
            LOOKUPVALUE(Table2[Column1],Table2[Number],_number),
            IF(
                _number>=4&&_number<=7,
                LOOKUPVALUE(Table2[Column2],Table2[Number],_number),
                IF(
                    _number>7,
                    LOOKUPVALUE(Table2[Column3],Table2[Number],_number)
                )
            )
        )
    )
    return
    SUMX(
        tab,
        [Result]
    )

     

    Result:

     

    Best Regards

    Allan

     

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