February 1, 2019
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.
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:
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
February 1, 2019
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:\Users\admin\Desktop\Newest Pull request\Vnomic-Generic-Azure-Master\PQ Example Cost Summary\Master\Sample.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
July 24, 2019
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:\Users\admin\Desktop\Newest Pull request\Vnomic-Generic-Azure-Master\PQ 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
February 1, 2019
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
July 24, 2019
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
February 1, 2019
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:
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
July 24, 2019
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.
1 Guest(s)