Forum Discussion
PS_78
2 years agoHelper II
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...
- 2 years 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)RETURNIF(_actual = _target, "Green", "Red") -- If they match, the result is "Green" otherwise, it's "Red"
muhammad_786_1
2 years agoSolution Supplier
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"
- PSivapuram2 years agoFrequent Visitor
Thanks muhammad_786_1 . Yeah, switch is one option but I do not want to use switch. Instead want to see if we can read dynamically (like we can do in SAP ABAP).
But thanks for your suggestion.
Regards,
PS