Extracting data

doriannjeshi

Board Regular
Joined
Apr 5, 2015
Messages
245
Office Version
  1. 365
Platform
  1. Windows
Hello,
I need help with extracting data from a large sheet based on table 1 to table 2 result

The length of the nr of rows to be copied down is determined by the column 3 which is always containing 0 .

TABLE1 dataTABLE2 result
COL1COL2COL3COL1COL2COL3
aaabbbvvvwaaabbbvvvw
12325000aaabbbvvvw
6494000aaabbbvvvw
4232000aaabbbvvvw
2965000aaabbbvvvw
abdcdcwewabdcdcwew
abd000abdcdcwew
abd000abdcdcwew
abd000abdcdcwew
a34223113a34223113
23000a34223113
2000a34223113
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Power query can help
Book1
ABCDEFGHIJK
1TABLE1 dataTABLE2 result
2COL1COL2COL3COL1COL2COL3COL1COL2COL3
3aaabbbvvvw
4aaabbbvvvwaaabbbvvvwaaabbbvvvw
5123250aaabbbvvvwaaabbbvvvw
664940aaabbbvvvwaaabbbvvvw
742320aaabbbvvvwaaabbbvvvw
829650aaabbbvvvwabdcdcwew
9abdcdcwewabdcdcwewabdcdcwew
10abd0abdcdcwewabdcdcwew
11abd0abdcdcwewabdcdcwew
12abd0abdcdcwewa34223113
13a34223113a34223113a34223113
14230a34223113a34223113
1520a34223113
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COL1", type any}, {"COL2", type any}, {"COL3", type any}}),
    #"Removed Top Rows" = Table.Skip(#"Changed Type",1),
    #"Filtered Rows" = Table.SelectRows(#"Removed Top Rows", each true),
    #"Added Conditional Column" = Table.AddColumn(#"Filtered Rows", "Custom", each if [COL3] = 0 then null else [COL1]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"COL1"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "COL2", "COL3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "COL1"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",0,null,Replacer.ReplaceValue,{"COL3"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"COL1", "COL2", "COL3"})
in
    #"Filled Down"
 
Upvote 0
Hi Kerryx, thank you for the solution !
First time using Powerquery : Editor gives me this error: We couldn't find an Excel table named 'table1'.
 
Last edited:
Upvote 0
Did you start by doing the following
1- Highlight the range for your source data , below it is "A2:C15"
2- Go to Data tab and click on Get Data -> from Table/ Range

As long as there are no other tables on the sheet it will convert this to Table1

If your sheet already has the source info in an existing table , select the table got to Table Design and find the existing table name , replace the name in the formula below with existing name if there


Here are some good links from @alansidman on how to set up and use PQ

How to use Power Query




1707377125637.png


1707377454140.png
 
Upvote 0
I dont know what I am doing wrong sth that got to do with the table
it gives me this error:
the column 'Col1" of the table wasnt found
 
Upvote 0
Did you tick this box when importing the range, this tells PQ that the top row in your selection are the headers for the columns
1707463952718.png

so when it is imported you have this
1707464019612.png


Click on Advanced editor, which will already contain the code as shown below, just delete that code and put in the code i have given you above , click on done, then LOad and close, select where in the excel sheet you want it to go., and Bob's your Aunty :)
1707464081153.png
 
Upvote 0
Thank you for the guide Kerryx, It was the headers

now not all data gets converted , the data below COL1 , COL3 dont get filled down
1707500283664.png
 
Upvote 0
Based on the codes these are the steps applied on the right of your screen, once you click on any step it will show you what has been done as you see in COL 3 , i had just 0 in some rows but reviewing your screenshots i see "000" so the step where the Additional column was added was not doing anything as it did not find 0 because it should have been looking for "000"
So just replace this line
Power Query:
#"Added Conditional Column" = Table.AddColumn(#"Filtered Rows", "Custom", each if [COL3] = "000" then null else [COL1]),

1707643618775.png
 
Upvote 0
Here is the full code with the replaced line and also had to change the replace value in COL3 as my original code had find 0 instead of find "000"
to replace with null, hopefully that should sort it all, i am assuming "000" is text format
Power Query:
let
 let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COL1", type any}, {"COL2", type any}, {"COL3", type any}}),
    #"Removed Top Rows" = Table.Skip(#"Changed Type",1),
    #"Filtered Rows" = Table.SelectRows(#"Removed Top Rows", each true),
    #"Added Conditional Column" = Table.AddColumn(#"Filtered Rows", "Custom", each if [COL3] = "000" then null else [COL1]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"COL1"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "COL2", "COL3"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "COL1"}}),
    #"Replaced Value" = Table.ReplaceValue(#"Renamed Columns","000",null,Replacer.ReplaceValue,{"COL3"}),
    #"Filled Down" = Table.FillDown(#"Replaced Value",{"COL1", "COL2", "COL3"})
in
    #"Filled Down"
"
 
Last edited:
Upvote 0
Solution

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top