0

I have a data as below. I need to create a calculated column in power query. Full name can be consisted of name, last name, middle name and, 2 letters (which should be added in the lastname). Many thanks in advance.

Full Name                                 Expected Answer
name1 lo lastname1                        name1. lolastname1                                        
name2 di lastname2                        name2. dilastname2
name3 secondname lastname3                name3.lastname3
name4 lastname4                            name4.lastname4
0

2 Answers 2

2

enter image description here

enter image description here

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykvMTTVUyMlXyEksLgFzlGJ1IMJGCimZcGEjuLCxQnFqcn5eCogNlzaGS5vAxUyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Full Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Full Name", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each let
a = Text.BeforeDelimiter([Full Name], " ")&".",
b = Text.BetweenDelimiters([Full Name], " ", " "), 
c = if b = "lo" or b = "di" then b else "",
d = Text.AfterDelimiter([Full Name], " ", {0, RelativePosition.FromEnd})

in a & c & d
)
in
    #"Added Custom"

Sign up to request clarification or add additional context in comments.

Comments

1

This will keep any pair of two letters and discard everything else:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WykvMTTVUyMlXyEksLgFzlGJ1IMJGCimZcGEjuLCxQnFqcn5eCogNlzaGS5vAxUyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Full Name" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Full Name", type text}}),
    #"Add Expected Answer" = Table.AddColumn(#"Changed Type","Expected Answer", (r)=>
            [a=Text.Split(r[Full Name]," "),
             b=List.Range(a,1,List.Count(a)-2),
             c=List.Select(b, each Text.Length(_)=2),
             d=if List.IsEmpty(c) then "" else c{0},
             e=List.First(a) & " " & d & List.Last(a)
            ][e], type text)
in
    #"Add Expected Answer"

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.