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
craig811
Helper III
Helper III

How do I use 'M' language to only load records before text 'Ending Balance for Period'

Hi ,

 

When I load my data into Power query or Power BI, I only want to load rows of data for all coulumns before the text '

Ending Balance for Period' found in Column1. Currently I have to use remove rows from the bottom using 'Remove Rows'. The only issue is it's not always the same amount of rows on each sheet. 

1 ACCEPTED SOLUTION

Hi @craig811,

 

Try this:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Threshold", each if [Column1] = "Ending Balance for Period" then 1 else 0),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Threshold"}, {{"Table", each _}}, GroupKind.Local),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index1", 0, 1),
    #"Expanded Table" = Table.ExpandTableColumn(#"Added Index", "Table", {"Column1", "Value"}, {"Column1", "Value"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Table", each ([Index1] = 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Threshold", "Index1"})
in
    #"Removed Columns"

GroupbyIndex.PNG

View solution in original post

2 REPLIES 2
Mariusz
Community Champion
Community Champion

Hi @craig811 

Can you make the data sample availeple?

Many Thanks

Mariusz 

Hi @craig811,

 

Try this:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Threshold", each if [Column1] = "Ending Balance for Period" then 1 else 0),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Threshold"}, {{"Table", each _}}, GroupKind.Local),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index1", 0, 1),
    #"Expanded Table" = Table.ExpandTableColumn(#"Added Index", "Table", {"Column1", "Value"}, {"Column1", "Value"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Table", each ([Index1] = 0)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Threshold", "Index1"})
in
    #"Removed Columns"

GroupbyIndex.PNG

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.

Top Solution Authors