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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

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. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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