Forum Discussion
Compiling a new column value from multiple columns if only one of them has a value per row?
- 3 years ago
eeviste , Try one of the two way to create a new columns
coalease([AgeGroup1],[UnknownAge],[UnknownAdult],[UnknownChild])
Switch(True() ,
not(isblank([AgeGroup1])) && [AgeGroup1]<>"", [AgeGroup1],
not(isblank([UnknownAge])) && [UnknownAge]<>"", [UnknownAge],
not(isblank([UnknownAdult])) && [UnknownAdult]<>"", [UnknownAdult],
not(isblank([UnknownChild])) && [UnknownChild]<>"", [UnknownChild])
eeviste , Try one of the two way to create a new columns
coalease([AgeGroup1],[UnknownAge],[UnknownAdult],[UnknownChild])
Switch(True() ,
not(isblank([AgeGroup1])) && [AgeGroup1]<>"", [AgeGroup1],
not(isblank([UnknownAge])) && [UnknownAge]<>"", [UnknownAge],
not(isblank([UnknownAdult])) && [UnknownAdult]<>"", [UnknownAdult],
not(isblank([UnknownChild])) && [UnknownChild]<>"", [UnknownChild])
- eeviste3 years agoNew Member
Thanks heaps for your help, amitchandak ! 👍
COALESCE did not work for me, but I got the SWITCH combo to work, thank you. In it though, for reasons I don't fully understand, I needed to swap around the variables and have AgeGroup1 last... Not sure why, but it works like this, so I am happy! 😄
This is my code in the end, with a little addition (that I didn't include in the original request for help, for clarity) where I wanted to limit the rows that get the combined value to humans (another variable in the same table), and others would be "not human".
AgeGroup7 = IF( data[Subject] = "Human", SWITCH( TRUE(), NOT(ISBLANK(data[UnknownAge])) && data[UnknownAge] <> "", data[UnknownAge], NOT(ISBLANK(data[UnknownAdult])) && data[UnknownAdult] <> "", data[UnknownAdult], NOT(ISBLANK(data[UnknownChild])) && data[UnknownChild] <> "", data[UnknownChild], NOT(ISBLANK(data[AgeGroup1])) && data[AgeGroup1] <> "", data[AgeGroup1], "not human" ), "not human")I think I will mark yours as the solution, even though there were some tweaks that were needed. It still cracked it for me. Thanks heaps again for your help! 👍