cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
richleeb2
Frequent Visitor

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
Super User I
Super User I

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!



View solution in original post

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

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

Top Solution Authors
Top Kudoed Authors