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
eng_123
Frequent Visitor

Rows between text to new column in power query

Hi All i could like to create a new custom column in power query whenever dynamic rows for employee names between Section - Employee HR, IT and Sales

1. employee information between HR and IT then new Column row should be HR. 

2. employee information between IT and Sales then new Column row should be IT.

3 or else Sales

Create 1,2 and 3 in new column example

 

Section - EmployeeNew Column Needs to be created
HR 
MaryHR
JillHR
SophieHR
IT 
WillIT
JimmyIT
RogerIT
Sales 
JohnSales
TomSales
LarrySales

 

 

Thank you

3 ACCEPTED SOLUTIONS
slorin
Super User
Super User

Hi @eng_123 

add a new column

if List.Contains({"HR", "IT", "Sales"}, [#"Section - Employee"]) then [#"Section - Employee"] else null

then fill down

 

Stéphane 

View solution in original post

ronrsnfld
Super User
Super User

This shows one method:

Paste the code into the Advanced Editor and explore the Applied Steps to understand

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghSitWJVvJNLKoEM7wyc3LAjOD8gozMVDDTMwRMhcOkvDJzcyGqg/LTU4sgyhNzUoshsvkZeWBGSH4umPZJLAIZHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Section - Employee" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Section - Employee", type text}}),
    #"Add new column" = Table.AddColumn(#"Changed Type","Section", each if List.Contains({"HR","IT","Sales"},[#"Section - Employee"])
            then [#"Section - Employee"] else null, type nullable text),
    #"Fill Down" = Table.FillDown(#"Add new column",{"Section"}),
    #"Null Matching" = Table.ReplaceValue(
        #"Fill Down",
        each [#"Section - Employee"],
        null,
        (x,y,z)as nullable text=> if List.Contains({"HR","IT","Sales"},y) then z else x,
        {"Section"})
in
    #"Null Matching"

 

 

 Results

ronrsnfld_0-1727089074506.png

 

 

View solution in original post

Omid_Motamedise
Super User
Super User

Easy to solve

 

Add a new column by the next formula, to reach the next image

 

if List.Contains({"HR","Sales","IT"},[#"Section - Employee"]) then [#"Section - Employee"] else null

Omid_Motamedise_0-1727133884483.png

 

 

then select the column Custom and from Transform tab pick Fill Down to reach 

Omid_Motamedise_1-1727133928878.png



the hole formula is

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghSitWJVvJNLKoEM7wyc3LAjOD8gozMVDDTMwRMhcOkvDJzcyGqg/LTU4sgyhNzUoshsvkZeWBGSH4umPZJLAIZHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Section - Employee" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if List.Contains({"HR","Sales","IT"},[#"Section - Employee"]) then [#"Section - Employee"] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"})
in
    #"Filled Down"






If my answer helped solve your issue, please consider marking it as the accepted solution.

View solution in original post

4 REPLIES 4
eng_123
Frequent Visitor

Thanks All. Much appriciate it for the solution.

Omid_Motamedise
Super User
Super User

Easy to solve

 

Add a new column by the next formula, to reach the next image

 

if List.Contains({"HR","Sales","IT"},[#"Section - Employee"]) then [#"Section - Employee"] else null

Omid_Motamedise_0-1727133884483.png

 

 

then select the column Custom and from Transform tab pick Fill Down to reach 

Omid_Motamedise_1-1727133928878.png



the hole formula is

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghSitWJVvJNLKoEM7wyc3LAjOD8gozMVDDTMwRMhcOkvDJzcyGqg/LTU4sgyhNzUoshsvkZeWBGSH4umPZJLAIZHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Section - Employee" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each if List.Contains({"HR","Sales","IT"},[#"Section - Employee"]) then [#"Section - Employee"] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Custom"})
in
    #"Filled Down"






If my answer helped solve your issue, please consider marking it as the accepted solution.
ronrsnfld
Super User
Super User

This shows one method:

Paste the code into the Advanced Editor and explore the Applied Steps to understand

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8ghSitWJVvJNLKoEM7wyc3LAjOD8gozMVDDTMwRMhcOkvDJzcyGqg/LTU4sgyhNzUoshsvkZeWBGSH4umPZJLAIZHgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Section - Employee" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Section - Employee", type text}}),
    #"Add new column" = Table.AddColumn(#"Changed Type","Section", each if List.Contains({"HR","IT","Sales"},[#"Section - Employee"])
            then [#"Section - Employee"] else null, type nullable text),
    #"Fill Down" = Table.FillDown(#"Add new column",{"Section"}),
    #"Null Matching" = Table.ReplaceValue(
        #"Fill Down",
        each [#"Section - Employee"],
        null,
        (x,y,z)as nullable text=> if List.Contains({"HR","IT","Sales"},y) then z else x,
        {"Section"})
in
    #"Null Matching"

 

 

 Results

ronrsnfld_0-1727089074506.png

 

 

slorin
Super User
Super User

Hi @eng_123 

add a new column

if List.Contains({"HR", "IT", "Sales"}, [#"Section - Employee"]) then [#"Section - Employee"] else null

then fill down

 

Stéphane 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.