Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mouzzampk
Helper I
Helper I

Power Query Consists of three numbers, followed by either X or D,

Hi,


I am having difficult time to list D or X if matches the criteria i.e., format consists of three numbers, followed by either X or D, followed by a further three numbers using power query. If matches the format then in Ouput column add X or D otherwise N.

 

Book1.xlsx

 

ListOutput
123X325X
254D365D
689X555X
784X444X
789D748D
ABCX899N
3456X879N
876X8555N
2466D854N

 

Thanks in advance.

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

@mouzzampk so many ways to do that...

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    repl = List.Buffer(List.Transform({"0".."9"}, (x) => {x, null})),
    x = {null, null, null, "X", null, null, null},
    d = {null, null, null, "D", null, null, null},
    fx = (txt) => 
        [lst = List.Buffer(List.ReplaceMatchingItems(Text.ToList(txt), repl)),
        check = if lst = x or lst = d then lst{3} else "N"][check],
    col = Table.AddColumn(Source, "Output", (x) => fx(x[List]))
in
    col

View solution in original post

2 REPLIES 2
AlienSx
Super User
Super User

@mouzzampk so many ways to do that...

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    repl = List.Buffer(List.Transform({"0".."9"}, (x) => {x, null})),
    x = {null, null, null, "X", null, null, null},
    d = {null, null, null, "D", null, null, null},
    fx = (txt) => 
        [lst = List.Buffer(List.ReplaceMatchingItems(Text.ToList(txt), repl)),
        check = if lst = x or lst = d then lst{3} else "N"][check],
    col = Table.AddColumn(Source, "Output", (x) => fx(x[List]))
in
    col

Thank you!!! 😇

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.