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
richleeb2
Helper I
Helper I

Assistance needed with formula for new column in Power BI

I want to create a 3rd column (New Name) with revised names for Test 1 in Name column.  For Test1, I want this to be named Test A IF Basket column is equal to xray1 or xray2.  But if the Basket is qual1 or qual 2, I want the new name to be Test B.  I want to keep the Test2 name the same.  Can you help with the formula?  Thanks!

 

Name

Basket

New Name
Test1

xray1

TestA
Test2bobTest2
Test1xray2TestA
Test2bobTest2
Test1qual1TestB
Test2bobTest2
Test1qual2TestB
Test2bobTest2

 

 

1 ACCEPTED SOLUTION

Could also be:

Column = 
SWITCH(
    TRUE(),
    LEFT(TableName[Basket],4) = "xray", "TestA",
    LEFT(TableName[Basket],4) = "qual", "TestB",
    FORMAT(TableName[Name],"0")
)

It's really hard for me to know what data types you're dealing with if they are not in your sample.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

5 REPLIES 5
ChrisMendoza
Resident Rockstar
Resident Rockstar

Try as:

Column = 
SWITCH(
    TRUE(),
    LEFT(TableName[Basket],4) = "xray", "TestA",
    LEFT(TableName[Basket],4) = "qual", "TestB",
    TableName[Name]
)

image.png






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



I tried this but got "Function 'SWITCH' does not support comparing values of type True/False with values of type Number. Consider using the VALUE or FORMAT function to convert one of the values."  What does the 4 do?  

So your sample was not representative (data types) of your actual data? My guess is try:

Column = 
SWITCH(
    TRUE(),
    LEFT(TableName[Basket],4) = "xray", "TestA",
    LEFT(TableName[Basket],4) = "qual", "TestB",
    VALUE(TableName[Name])
)

 or maybe this:

Column = 
SWITCH(
    TRUE(),
    LEFT(VALUE(TableName[Basket]),4) = "xray", "TestA",
    LEFT(VALUE(TableName[Basket]),4) = "qual", "TestB",
    TableName[Name]
)

or all of both of them combined.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Could also be:

Column = 
SWITCH(
    TRUE(),
    LEFT(TableName[Basket],4) = "xray", "TestA",
    LEFT(TableName[Basket],4) = "qual", "TestB",
    FORMAT(TableName[Name],"0")
)

It's really hard for me to know what data types you're dealing with if they are not in your sample.






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



THe first one worked, I just changed the number to the actual length of the word.  Thanks!

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.