Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi, I am trying to combine multiple number columns (with IF statements).
Example
IF ([Apples]=1,"Apples","")
| Customer | Apples | Grapes | Oranges | Required Results Column |
| A | 1 | 1 | 0 | Apples | Grapes |
| B | 1 | 1 | 1 | Apples | Grapes |Oranges |
| C | 0 | 1 | 1 | Grapes|Oranges |
I am using the existing fields elsewhere so don't want to convert them to strings so require them to stay as number columns.
I have tried CONCATENATEX but failed.
Any help would VERY much be appreciated!
Solved! Go to Solution.
Hi
You could use thise formula in a new column
Result = IF(Customers[Apples] = 1; "Apples |";"") & IF(Customers[Grapes] =1;" Grapes |";"") &IF(Customers[Oranges] = 1; " Oranges |";"")
This is not a handy solution if you have more column values to check. Would it be a possible to unpivot the table in Power Query giving it a structure like this?
Customer | Fruit
============
Cust. A | Apples
Cust. A | Grapes
Cust. B | Apples
Cust. B | Grapes
Cust. B | Oranges
Cust. C | Grapes
Cust. C | Oranges
I hope this helps!
JJ
Hi, this a solution but the problem is the code growth depends or yor number of columns
FruitsByCustomer =
IF ( Customers[Apples] = 1, "Apples" )
& IF ( Customers[Grapes] = 1, IF ( Customers[Apples] = 1; "|Grapes","Grapes" ) )
& IF (
Customers[Oranges] = 1,
IF (
OR ( Customers[Apples] = 1; Customers[Grapes] = 1 ),
"|Oranges",
"Oranges"
)
)
Hi
You could use thise formula in a new column
Result = IF(Customers[Apples] = 1; "Apples |";"") & IF(Customers[Grapes] =1;" Grapes |";"") &IF(Customers[Oranges] = 1; " Oranges |";"")
This is not a handy solution if you have more column values to check. Would it be a possible to unpivot the table in Power Query giving it a structure like this?
Customer | Fruit
============
Cust. A | Apples
Cust. A | Grapes
Cust. B | Apples
Cust. B | Grapes
Cust. B | Oranges
Cust. C | Grapes
Cust. C | Oranges
I hope this helps!
JJ
@DoubleJBingo!, thank you so much. I was nearly there with that, but the brain just went cold. Thank you very much
@tanyad you are welcome
by the way, to remove the trailing "|" you could add another column with this code:
Fruits = LEFT(Customers[Result];LEN(Customers[Result])-1)
JJ
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 52 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 73 | |
| 70 | |
| 39 | |
| 34 | |
| 23 |