Forum

Extracting tables a...
 
Notifications
Clear all

Extracting tables and another data from folder path from multiple workbooks

11 Posts
2 Users
0 Reactions
273 Views
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi Guys,

I have folder and in this folder i have multiple the same structure workbooks with the same tables which i want to merge into one big summary table.Screenshot_22.png

In first tab i have tableToMerge, in worksheet Decription there is one cell named range "Description" with string inside for example "Workbook 1 User" and i have also mapping table where i have IndexTopo Column mapped for each Topology from TableToMerge worksheet. 

What i want to get is summary workbook like here:

Screenshot_24.png

On red i marked columns which i want to add with PQ. 

So from Summary workbook i want to:

1. Build PQ to loop through multiple workbooks in folder path provided (worksheet "FolderPathParameter")

2. Merge all tables t_MergeTable from worksheets tabletoMerge from each workbook

3. Provide also workbook path, description and IndexTopo from mapping table into Summary workbook.

I am attaching example files.

Please help,
Thank you in advance,
Best,
Jacek

 
Posted : 31/12/2019 2:38 am
(@gue19)
Posts: 8
Active Member
 

You can find my solution in the attachment.

I used functions to

- read your parameter "File Path" 

- read Table1 on sheet TableToMerge of each file and

- read Named Range "Description" on sheet "Description" of each file

to get the result

best regards,

Guenter

 
Posted : 03/01/2020 5:39 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Thank you very much!

Your solution is very nice ! But i have to analyze it more and i will come back with questions.

Best,
Jacek

 
Posted : 04/01/2020 3:30 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi Guenter Weber,

i analyzed your queries and they are awesome. 

I have one more question for you.
I want to add function which will be retriving range from worksheet.

What i achieved is writing standard query:

let
DynamicSource = "C:UsersadminDesktopNewest Pull requestVnomic-Generic-Azure-MasterPQ Example Cost SummaryMasterSample.xlsm",
Source = Excel.Workbook(File.Contents(DynamicSource), null, true),
#"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Deployment Costs")),
#"Expanded Data" = Table.ExpandTableColumn(#"Filtered Rows", "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7"})
in
#"Expanded Data"

How can i write function to read from specific worksheet name from specific workbook from folder?
I do not know why PQ treats this sheets as table - there is also formatted range in a shape of table but there is no table object, just data. 

I am attaching workbooks with sample worksheet as range "Deployment Costs".

To sum up:

I want to create a function fnGetWorksheet which will be get parameters like Folder path & workbook name, worksheetName to read data from worksheet from specific workbook and folder.

Please help,
Jacek

 
Posted : 07/01/2020 6:25 am
(@gue19)
Posts: 8
Active Member
 

Hi Jacek,

only a small modification is required. Then you can use it as a function (as long neither worksheet name and number of columns are changing!)

---------------------------

(DynamicSource as text) =>

let
  // DynamicSource = "C:UsersadminDesktopNewest Pull requestVnomic-Generic-Azure-MasterPQ Example Cost",

  Source = Excel.Workbook(File.Contents(DynamicSource), null, true),
  #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "Deployment Costs")),
  #"Expanded Data" = Table.ExpandTableColumn(#"Filtered Rows", "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7"})
in
  #"Expanded Data"

-------------------------

if you also want to use different worksheet names, then change

(DynamicSource as text) =>  to (DynamicSource as text, WorksheetName as text) =>

and ...each ([Name] = "Deployment Costs")), to ... each ([Name] = WorksheetName)),

 

but be aware that your column names or number of columns may also change. You can overcome this by using here also a dynamic aproach for column names and numbers.

regards,

guenter 

 
Posted : 08/01/2020 10:34 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Thank you very much! 

O wow this is working like a charm.

You can overcome this by using here also a dynamic aproach for column names and numbers.

How can i do number of columns dynamic when range change? Something like used range? 

Best Wishes,
Jacek

 
Posted : 09/01/2020 3:59 am
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

And one more issue i have with your poqwer query:

#"Added TopoIndex" = Table.AddColumn(#"Removed Columns1", "TopoIndex", each "Index" & [Topology]),

Here you are avoiding merging tables but i have to do this. In sample there is easy workaround like you did but whole purpose is to merge tables. 
But when i am mergind them instead of writing workaround - i am getting :

Formula.Firewall: Query (step 'Import each TableToMerge') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.

I can not definitely workaround this because in merged tables i can have a lot of other information which i can not put in the functions...

How can i avoid this error?

In attachement sample workbook.

Best,
Jacek

 
Posted : 09/01/2020 7:03 am
(@gue19)
Posts: 8
Active Member
 

Hi Jacek,

ad 6) as long as your tables look the same you can directly use the column names because they will not change (I assume) and therefore also the number is always the same. With this direct approach you are also able to modify some data directly.

If you use a more generic approach you may not know now how data manipulation will look like and therefore must be done outside of this function.

As every time it is easier if you have a specific example than talking very generic. 

 

ad 7)

Here you are avoiding merging tables but i have to do this. In sample there is easy workaround like you did but whole purpose is to merge tables. 

This I do not understand. What do you mean with workaround?

What is your expected result? Can you put a sample in you summary file?

Please also give a sample for the final table of the deployment costs (I think you also have something in mind because of your trial and question about your query change to a function)

For the Firewall problem: I do not know which tables you want to merge and I do not get this error. There are a lot of explanations about root causes and solutions on the internet.

I can not definitely workaround this because in merged tables i can have a lot of other information which i can not put in the functions...

too generic for me. Give me some more information/examples, then I may be able to help you. 

 cheers,

Guenter

 
Posted : 10/01/2020 2:13 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Hi Guenter,

thank you.

Let's focuc first on ad 7)

This I do not understand. What do you mean with workaround?

You added custom columns with formula and i need just do Merge queries (left join) in order to combine tables.

What i need to get is table like here:

Screenshot_1.png

So in source workbooks i have only 2 tables. 
And in result table i have to join them. 

let
pFolder=fnGetParameter("File Path"),
Source = Folder.Files(pFolder),
#"Filtered Rows" = Table.SelectRows(Source, each not Text.StartsWith([Name], "~") and Text.StartsWith([Extension], ".xls")),
#"Import each TableToMerge" = Table.AddColumn(#"Filtered Rows", "Imported", each fnSingleFileImport([Folder Path] & [Name], "t_MergeTable", "Table")),
#"Removed Columns" = Table.RemoveColumns(#"Import each TableToMerge",{"Content", "Extension", "Date accessed", "Date modified", "Date created", "Attributes"}),
#"Expanded Imported" = Table.ExpandTableColumn(#"Removed Columns", "Imported", {"Topology", "Server"}, {"Topology", "Server"}),
#"Removed Columns1" = Table.RemoveColumns(#"Expanded Imported",{"Name", "Folder Path"}),
#"Merged Queries" = Table.NestedJoin(#"Removed Columns1", {"Topology"}, t_MappingTable, {"Imported.Topology"}, "t_MappingTable", JoinKind.LeftOuter)
in
#"Merged Queries"

In step #Merged Queries i am getting this firewall error. 
What will be the solution in this case? 

I know that there is a lot solutions but i can not refer them to our specific example. 

What did you do? Just turn of privacy setting in Excel? 
Maybe there is another work around?

Best,
Jacek

 
Posted : 14/01/2020 3:45 am
(@gue19)
Posts: 8
Active Member
 

I used your example files and may be the info there was too simple. in your latest attachment I can only see a result without source (sample files).

Firewall: Up to now (I have no "external" sources) I only had this problem when I copied a workbook to another computer. I always turned off the privacy settings . What you can do is that you rename/remove this function and redo it step by step by yourself (same code) but I do not know if the really helps. Sometimes it worked for me.

I also read that sometimes this error is dependend on the version of Excel (build) and Power Query.  YOu only can try all solutions you find in the WEB.

 
Posted : 16/01/2020 6:28 pm
(@jaryszek)
Posts: 177
Reputable Member
Topic starter
 

Thank you Guenter,

I only had this problem when I copied a workbook to another computer

Exactly. When i sharing file in somebody else computer there can be an issue. 

I will create separate topic about this. 

Thank you for your help and support,
Best wishes,
Jacek

 
Posted : 17/01/2020 2:53 am
Share: