Forum Discussion

PS_78's avatar
PS_78
Helper II
1 year ago
Solved

Read values dynamically

Hello - Is it possible to read value from a column dynamically? Please consider the scenario below and suggest.   I have a table (Color) with below structure.   Color Actual Trgt_White Trgt...
  • muhammad_786_1's avatar
    1 year ago

    I think It can work for you. You can create a calculated column like that.

     

    Result =
    VAR _color = 'Color'[Color]
    VAR _actual = 'Color'[Actual]
    VAR _target =
        SWITCH(
            _color,
            "White", 'Color'[Trgt_White], -- If _color is "White", return the value from Trgt_White column
            "Blue", 'Color'[Trgt_Blue],  -- If _color is "Blue", return the value from Trgt_Blue column
            "Black", 'Color'[Trgt_Black] -- If _color is "Black", return the value from Trgt_Black
        )
    RETURN
        IF(_actual = _target, "Green", "Red") -- If they match, the result is "Green" otherwise, it's "Red"