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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Pivot table in power query

hello, there is a help to make the Pivot table in the picture in a power query.

Alidefne_1-1690014389841.png

 

Picture of the table below. It will make the job much easier and simpler in a situation like the first picture.

Alidefne_0-1690014354285.png

 

https://1drv.ms/x/s!AmP8SNf-sgJ7n05LkqLxDYSprZTj?e=bMvHMq   

1 ACCEPTED SOLUTION

ThisWorkbook.Connections("Combined_Financials_Sector").Refresh

 

note that Background refresh option should be checked. In the Excel UI, you can access this setting by clicking on "Connections" in the "Data" ribbon, selecting a connection, and clicking on "Properties". The "Enable background refresh" setting is in the dialog box that opens.

 

rubayatyasmin_0-1689517080227.png

 

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

16 REPLIES 16
Manoj_Nair
Solution Supplier
Solution Supplier

@Anonymous- Check this PBIX file out. Let me know if this works for you.

 

https://github.com/msncps/Power-BI-Community/blob/main/2023_07_22_Pivot%20table%20in%20power%20query.pbix 

 

As @rubayatyasmin suggested, you can accomplish this by utilizing the Matrix visuals. In the attached file, you'll find the specific steps that were followed. Moreover, you can reach the same outcome by deactivating the SteppedLayout and adopting the classic style.

Anonymous
Not applicable


Hi @Manoj_Nair 
This is not the Result I want.
in the Template below.
Can this result be done with the power query in excel?

 

Alidefne_1-1690014389841.png

To my knowledge, you can not achieve the same result in PQ. 

 

I am curious if it's possible. Let me know here if you are able to accomplish it in PQ. Maybe some advanced M code can do the trick. 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

you're right, it's a difficult process.
If I import it directly from the power query as a pivot table report, I have a problem.

I am currently renewing with these codes.

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        
Sheets("Combined_Financials").Range("Combined_Financials_Sector").ListObject.QueryTable.Refresh BackgroundQuery:=True
Sheets("Symbols_Price").Range("Combined_Price_Sector").ListObject.QueryTable.Refresh BackgroundQuery:=True
End Sub

 How do I refresh the "Combined_Financials_Sector" in the background.

ThisWorkbook.Connections("Combined_Financials_Sector").Refresh

 

note that Background refresh option should be checked. In the Excel UI, you can access this setting by clicking on "Connections" in the "Data" ribbon, selecting a connection, and clicking on "Properties". The "Enable background refresh" setting is in the dialog box that opens.

 

rubayatyasmin_0-1689517080227.png

 

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

Alidefne_0-1690213730338.pngAlidefne_1-1690213796818.png

I did what you said but I am getting error.

Can you paste the error? It would be easy to troubleshoot. 

 

Thanks


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

@Anonymous 

 

 

The "Run-time error 9: Subscript out of range" typically occurs when the specified object or element does not exist within the collection. In this case, the error is likely due to the fact that there is no connection named "Combined_Financials_Sector" in the workbook connections.

To resolve this error, you should check if the connection name is correct and make sure that the connection exists in the workbook. To verify the connection name, you can follow these steps:

  1. Open your Excel workbook.
  2. Click on the "Data" tab in the ribbon.
  3. Click on "Connections" to view the workbook connections.
  4. Look for the connection named "Combined_Financials_Sector" in the list of connections. If it's not there, you may have used a different name or the connection might have been deleted.

If you find the correct connection name, you can use the following VBA code to refresh the connection in the background with the "Enable background refresh" option checked:

 

Sub RefreshConnectionInBackground() On Error Resume Next ThisWorkbook.Connections("Combined_Financials_Sector").Refresh On Error GoTo 0 End Sub

This code will try to refresh the connection, and if it doesn't find the connection, it will simply resume the code without raising an error. However, it's essential to make sure that the connection name is correct and exists in the workbook.

If you are still encountering the error after verifying the connection name, please double-check the name spelling and ensure that there are no typos or extra spaces in the connection name. Also, make sure that the connection is created before trying to refresh it programmatically.

 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

I checked what you wrote but there is no workbook link.

I checked what you wrote but there is no workbook link.
I am updating the pivot table.

Private Sub CommandButton1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
        

Sheets("Symbols_Price").Range("Combined_Price_Sector").ListObject.QueryTable.Refresh BackgroundQuery:=True


Worksheets("PT_C").PivotTables("PivotTable1").PivotCache.Refresh



End Sub

Alidefne_0-1690221566192.png

 

It continues to download in the background but I get another error.
Actually, I just need to press "end" for the refresh to finish.

Sorry, this is not English. I can not read it. 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

@rubayatyasmin 
"note that Background refresh option should be checked. In the Excel UI, you can access this setting by clicking on "Connections" in the "Data" ribbon, selecting a connection, and clicking on "Properties". The "Enable background refresh" setting is in the dialog box that opens."

I marked the place you mentioned here. but still i am getting error.

 

Anonymous
Not applicable

This may be the poorest table design I've ever seen. 

Anonymous
Not applicable

If you have an opinion on the problem, I'd love to hear it.What is the Bad Thing?


Düştüm mapus damlarına öğüt veren bol olur
Toplasam o öğütleri burdan köye yol olur

rubayatyasmin
Super User
Super User

Hi, @Anonymous 

 

this is what I could achieve in PQ

 

rubayatyasmin_0-1690022367511.png

though not an exact pivot table like Excel. You could use Power BI matrix visual as an alternative to the Excels pivot table. 

 

rubayatyasmin_0-1689517080227.png

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Anonymous
Not applicable

It's far from the result I want. I am already using the result you showed. thanks

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors