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

help on conditional formatting or nested if

hi all

I have a list of customer id from the system which is not accurate, is it possible to achieve the following with power bi as a new column? Any advice is appreciated.

 

123.JPG

Thank you so much!

1 ACCEPTED SOLUTION
themistoklis
Community Champion
Community Champion

@kokoro_1202 

 

Try the following formula:

New Column = 
SWITCH( TRUE(),
LEFT(Table[CustomerID],1) = "w" , Table[CustomerID],
LEFT(Table[CustomerID],3) = "000" , "u" & Table[CustomerID],
LEN(Table[CustomerID]) = 3 , "z" & Table[CustomerID],
"Other"
)

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

1. Create a new column for Result field

Result = If ( Len(Cust[CustomerID]) = 3 , "Z" & Cust[CustomerID] , IF( LEFT(Cust[CustomerID],3) = "000" , "U"&Cust[CustomerID],Cust[CustomerID]))


2. Create an another column for font formatting.

FontId = If ( Len(Cust[CustomerID]) = 3 , 1 , IF( LEFT(Cust[CustomerID],3) = "000" , 2 ,3))
 
3. Go to format pane and select Value "Result" from Conditional Formatting pane and enable Font color and follow as per the below screenshot

 

swathi_20_0-1616504796311.png

 

themistoklis
Community Champion
Community Champion

@kokoro_1202 

 

Try the following formula:

New Column = 
SWITCH( TRUE(),
LEFT(Table[CustomerID],1) = "w" , Table[CustomerID],
LEFT(Table[CustomerID],3) = "000" , "u" & Table[CustomerID],
LEN(Table[CustomerID]) = 3 , "z" & Table[CustomerID],
"Other"
)

@themistoklis 

how shoulld the formula be to "a" to replace 000 i tried replace but it doesnt work?

Replace = (Table[CustomerID],1,3,"a"),
could you advice me again?

Anonymous
Not applicable

Hi @kokoro_1202 

This might help your requirement 

Result = If ( Len(Cust[CustomerID]) = 3 , "Z" & Cust[CustomerID] , IF( LEFT(Cust[CustomerID],3) = "000" , "U"&SUBSTITUTE(Cust[CustomerID],"000","a"),Cust[CustomerID]))

The formula should be

 

Column = REPLACE(Table[CustomerID],1,3,"a")

@themistoklis 

Tried the following, but it say "Function 'SWITCH' does not support comparing values of type True/False with values of type Text. Consider using the VALUE or FORMAT function to convert one of the values."

 

New Column =
SWITCH( TRUE(),
LEFT(Table[CustomerID],1) = "w" , Table[CustomerID],
REPLACE(Table[CustomerID],1,3,"a"),
LEN(Table[CustomerID]) = 3 , "z" & Table[CustomerID],
"Other"
)

@kokoro_1202 

 

Try this:

New Column = 
SWITCH( TRUE(),
LEFT(Table[CustomerID],1) = "w" , Table[CustomerID],
LEFT(Table[CustomerID],3) = "000" , REPLACE(Table[CustomerID],1,3,"a"),
LEN(Table[CustomerID]) = 3 , "z" & Table[CustomerID],
"Other"
)

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.