Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tanyad
Advocate III
Advocate III

Combine multiple columns - number to string

Hi,  I am trying to combine multiple number columns (with IF statements).

 

Example

 

IF ([Apples]=1,"Apples","")

 

CustomerApplesGrapesOrangesRequired Results Column
A110Apples | Grapes
B111Apples | Grapes |Oranges
C011Grapes|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!

 

1 ACCEPTED SOLUTION
DoubleJ
Solution Supplier
Solution Supplier

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

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@tanyad

 

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"
        )
    )



Lima - Peru
DoubleJ
Solution Supplier
Solution Supplier

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

DoubleJ
Solution Supplier
Solution Supplier

@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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.