Virtual column expression to create a 'switch' list of values from multiple fields

Hi community,

I've been struggling with this for some time so hoping someone might know the answer.

Consider the following table and data:

AppleBananaOrangePearLemon
TRUEFALSETRUETRUEFALSE
FALSETRUETRUETRUEFALSE
FALSETRUETRUETRUETRUE

I want to create a 6th column, a virtual column (type is list), to create a list from each of these five fields, where only the value is included if it is TRUE, and 'switch' it for a string (the column header). Here is the desired output, structured as a list.

AppleBananaOrangePearLemonVirtual Column
TRUEFALSETRUETRUEFALSEApple, Orange, Pear
FALSETRUETRUETRUEFALSEBanana, Orange, Pear
FALSETRUETRUETRUETRUEBanana, Orange, Pear, Lemon

This is the closest I can get:

 

 

CONCATENATE(
  IFS([Apple] = "TRUE", "Apple", ""),
  IFS([Banana] = "TRUE", "Banana", ""),
  IFS([Orange] = "TRUE", "Orange", ""),
  IFS([Pear] = "TRUE", "Pear", ""),
  IFS([Lemon] = "TRUE", "Lemon", "")
)

 

 

However this results in a trailing comma.

Any help appreciated.

Solved Solved
0 3 122
1 ACCEPTED SOLUTION

Please try 

LIST(IF([Apple], "Apple",""),
IF([Banana], "Banana",""),
IF([Orange], "Orange",""),
IF([Pear],"Pear",""),
IF([Lemon],"Lemon","")
)-LIST("")

for the first example with fruit names. Please replicate suitably for the second example of days.

[Apple], [Banana]......[Lemon] are assumed to be Y/N type columns.

View solution in original post

3 REPLIES 3

Please try 

LIST(IF([Apple], "Apple",""),
IF([Banana], "Banana",""),
IF([Orange], "Orange",""),
IF([Pear],"Pear",""),
IF([Lemon],"Lemon","")
)-LIST("")

for the first example with fruit names. Please replicate suitably for the second example of days.

[Apple], [Banana]......[Lemon] are assumed to be Y/N type columns.

It would be better to use just a normal column as all values are coming from the same and one row. Using IFS() would also be more simple 😉

Yes , correct @AleksiAlkio 

Top Labels in this Space