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
Digger
Post Patron
Post Patron

extract (leave only) all rows between two specific strings in a dataframe

I have table

 

Digger_0-1628255242683.png

How extract (leave only) all rows between two specific strings in a dataframe
total_sale_amount  and type

 

expected result

0.00

7037.65

 

Maybe using python?

 

Tryed this

 

 

import numpy as np

idx_start = dataset.index[dataset.Column1 == "total_sale_amount"]
idx_end = dataset.index[dataset.Column1 == "type"]
print(idx_start)

good = list(zip(list(idx_start), list(idx_end)))#required sequences

#unpack list of list
g2 = [list(range(x[0],x[1]+1)) for x in good]

#data.iloc[np.r_[[y for x in g2 for y in x]]]#If you want to return just the valid dataset

l =[y for x in g2 for y in x]

#'dataset'['mark'] = np.where((dataset.index.isin(l)),1,None)

 

But it return same result as dataset

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Digger ,

Here are the steps you can follow:

1. Enter Power Query through Transform data, select Table-right click-Duplicate to form a new table Table_duplicate.

vyangliumsft_0-1628501095899.png

2. Select Table, Add Column – Index Column – From 1.

vyangliumsft_1-1628501095904.png

3. Select the new table Table_duplicate, Add Column – Index Column – From 0.

vyangliumsft_2-1628501095907.png

4. Select Home – Merge Queries - Merge Queries as New

vyangliumsft_3-1628501095914.png

5. Enter the Merge interface, select the same [Index], Join kind = Left Outer

vyangliumsft_4-1628501095916.png

Result:

vyangliumsft_5-1628501095919.png

6. Create calculated table.

final_table =
var _1=FILTER('Merge1','Merge1'[Column1]="total_sale_amount")
return
SELECTCOLUMNS(_1,"Column1",[Column_merge])

7. Result:

vyangliumsft_6-1628501095920.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Digger ,

Here are the steps you can follow:

1. Enter Power Query through Transform data, select Table-right click-Duplicate to form a new table Table_duplicate.

vyangliumsft_0-1628501095899.png

2. Select Table, Add Column – Index Column – From 1.

vyangliumsft_1-1628501095904.png

3. Select the new table Table_duplicate, Add Column – Index Column – From 0.

vyangliumsft_2-1628501095907.png

4. Select Home – Merge Queries - Merge Queries as New

vyangliumsft_3-1628501095914.png

5. Enter the Merge interface, select the same [Index], Join kind = Left Outer

vyangliumsft_4-1628501095916.png

Result:

vyangliumsft_5-1628501095919.png

6. Create calculated table.

final_table =
var _1=FILTER('Merge1','Merge1'[Column1]="total_sale_amount")
return
SELECTCOLUMNS(_1,"Column1",[Column_merge])

7. Result:

vyangliumsft_6-1628501095920.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

lbendlin
Super User
Super User

this is easy to do via an index column. Please provide sample data in usable format (not as a picture).

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.

Top Solution Authors
Top Kudoed Authors