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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
v-yangliu-msft
Community Support
Community Support

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
v-yangliu-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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