Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Solved! Go to Solution.
I managed to reach a solution by using Macro. Not sure if this can be achieved by any other way.
The task was to import an input table into PQWRY and generating two outputs and print them upon refresh.
Sheet 1 contains Raw data and Sheet 2 and 3 contains output generated by PQWRY- https://drive.google.com/open?id=0B7imabOIHE8QTTFBLWw4aFU5dzg
Sub Macro1()
'
' Macro1 Macro
'
'
With ActiveWorkbook.Connections("Query - Table1").OLEDBConnection
.BackgroundQuery = False
.CommandText = Array("SELECT * FROM [Table1]")
.CommandType = xlCmdSql
.Connection = _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table1;Extended Properties="""""
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query - Table1")
.Name = "Query - Table1"
.Description = "Connection to the 'Table1' query in the workbook."
End With
With ActiveWorkbook.Connections("Query - Table1 (2)").OLEDBConnection
.BackgroundQuery = False
.CommandText = Array("SELECT * FROM [Table1 (2)]")
.CommandType = xlCmdSql
.Connection = _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table1 (2);Extended Properties="""""
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query - Table1 (2)")
.Name = "Query - Table1 (2)"
.Description = "Connection to the 'Table1 (2)' query in the workbook."
End With
ActiveWorkbook.RefreshAll
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Sheets("Sheet3").Select
Range("Table1__2[[#Headers],[Name]]").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End SubIf there any more ways to achieve I would be very intersted to know.
I managed to reach a solution by using Macro. Not sure if this can be achieved by any other way.
The task was to import an input table into PQWRY and generating two outputs and print them upon refresh.
Sheet 1 contains Raw data and Sheet 2 and 3 contains output generated by PQWRY- https://drive.google.com/open?id=0B7imabOIHE8QTTFBLWw4aFU5dzg
Sub Macro1()
'
' Macro1 Macro
'
'
With ActiveWorkbook.Connections("Query - Table1").OLEDBConnection
.BackgroundQuery = False
.CommandText = Array("SELECT * FROM [Table1]")
.CommandType = xlCmdSql
.Connection = _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table1;Extended Properties="""""
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query - Table1")
.Name = "Query - Table1"
.Description = "Connection to the 'Table1' query in the workbook."
End With
With ActiveWorkbook.Connections("Query - Table1 (2)").OLEDBConnection
.BackgroundQuery = False
.CommandText = Array("SELECT * FROM [Table1 (2)]")
.CommandType = xlCmdSql
.Connection = _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Table1 (2);Extended Properties="""""
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = ""
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Query - Table1 (2)")
.Name = "Query - Table1 (2)"
.Description = "Connection to the 'Table1 (2)' query in the workbook."
End With
ActiveWorkbook.RefreshAll
Sheets("Sheet2").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
Sheets("Sheet3").Select
Range("Table1__2[[#Headers],[Name]]").Select
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
IgnorePrintAreas:=False
End SubIf there any more ways to achieve I would be very intersted to know.
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 58 | |
| 45 | |
| 41 | |
| 21 | |
| 18 |