cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

new column based on specific text within a column

I am trying create a new column in a table based on [fpartno] where:

 

- if the 14th digit of the [fpartno] is F, the value in the new column should show "RC_FP"

- if the 14th digit of the [fpartno] is R, the value in the new column should show "RC_RP"

- and if the 14th digit is neither, then the new column should be empty.

 

I created this:

cRCtest = SWITCH(TRUE (),
SEARCH("F", 'dbMfgUnits'[fpartno],,0) =14, "RC_FP",
SEARCH("R", 'dbMfgUnits'[fpartno],,0) =14, "RC_RP"
)
 
I get the expected result for the "RC_FP", but not for the "RC_RP".   Can anyone help?
1 ACCEPTED SOLUTION
Super User III
Super User III

@alittle1 

Ah, of course. I did not realize at first sight. What you are doing is looking for the position of the first R or first F. And that can be before the position 14 (even if there's an "R" at position 14) What you actually need is to extract the character in position 14 and then check if it is an R or an F:

 

cRCtest V2 =
SWITCH (
    RIGHT ( LEFT ( dbMfgUnits[fpartno], 14 ), 1 ),
    "R", "RC_FP",
    "F", "RC_RP"
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

4 REPLIES 4
Super User III
Super User III

@alittle1 

Ah, of course. I did not realize at first sight. What you are doing is looking for the position of the first R or first F. And that can be before the position 14 (even if there's an "R" at position 14) What you actually need is to extract the character in position 14 and then check if it is an R or an F:

 

cRCtest V2 =
SWITCH (
    RIGHT ( LEFT ( dbMfgUnits[fpartno], 14 ), 1 ),
    "R", "RC_FP",
    "F", "RC_RP"
)

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

View solution in original post

Thank you!  That worked!

Super User III
Super User III

Hi @alittle1 

Your code looks sound. Can you share some data with examples where it does not work?

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

 

Value

0P9RC15A25020R0-FSC:  expected result "RC-RP"; actual result = empty field

0P9RC17L50160FS-FXC-03:  expected result "RC-FP"; actual result "RC-FP"

0P9RC22A25050R0-XSC:  expected result "RC-RP"; actual result = empty field

0P9RC22A75020F2-FSC-C01:  expected result "RC-FP"; actual result "RC-FP"

 

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors