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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MelvinM
Frequent Visitor

How to manage PowerBI reports with code ?

Hello everyone !

 

I currently work at a company where I design PowerBI reports for our clients. Having a large number of clients, we would like to automate the process of creating and maintaining the reports with code.

 

In idea, we would like to be able to get the code for a "master report" so that we can modify it directly with code without having to open PowerBI. This would not only automate the process of creating a report by duplicating the master report and making all the necessary modifications with code, but also its maintenance. Indeed, when we make a change in a report, we must currently do it manually for all other clients which is very time consuming.

 

The structure of the reports is identical for each of the clients except for a few details:

  • The SQL query to connect to BigQuery to get the client's data
  • The pages that are shown or hidden (depending on the client, the same number of pages are not shown)
  • The title of 2 slicers
  • The presence or not of 2 slicers depending on the presence of attributes associated with the slicer in the database.
  • The title of some pages


I have done a lot of research on how to do this, I have done some tests but I can't really find a solution that works. Here are the tracks I explored:

  • Power BI Rest API, which allows you to duplicate a report, change the parameters of a report (so potentially the SQL query) but not change the visual of the report.
  • PowerBI Javascript API, which obviously allows you to direct the visual of the report with code by embedding it in an application, but the visual changes do not seem to apply directly to the report in PowerBI service but just in the application. Also, I don't see any methods to change the title of a visual, page or hide a page.
  • Extract the code from the .pbix file by converting it to .zip. However, when I modify for example the displayname attribute of a slicer in the Layout file and convert the .zip file back to .pbix, an error message appears indicating that the file is corrupted.

 

Do you know if one of the tracks I mentioned can achieve what I want to do? Is there any other way to automate the creation and maintenance of reports ? Do I miss something in my way of thinking ?

 

Thank you in advance for your advice!

 

Melvin

1 ACCEPTED SOLUTION

Hi!

 

1. Opened the Layout file in Notepad++

2. Saved the file in other location as .txt

3. Made changes in Layout file

4. Saved my changes and closed the Layout.txt file

5. Removed the extension .txt from the file in the File Explorer.

6. Copied the file and pasted it in the Report folder in the report zip file

7. Changed the extension of the report file from .zip to .pbix

 

Regards

Fredrik

View solution in original post

3 REPLIES 3
FredrikJ
Helper II
Helper II

Hello Melvin!

I have used your third option with success. This is the steps I used to avoid the file getting corrupted.

 

1. Rename to .zip
2. Delete the SecurityBindings file
3. Remove <Override PartName="/SecurityBindings" ContentType="" /> in the [Content_Types].xml file
4. Open the file Layout and do my changes in Notepas ++

5. Rename the file to .pbix again

 

I do not extract the zip file at any time.

Regards

Fredrik

Hello FredrikJ !

 

First of all, thank you for your reply. I have tried what you said, however it seems that I am not able to save the changes I made in the Layout file when I open it without decompressing the whole folder. I can't overwrite the file while i was able to dot it when the whole folder was decrompressed. 

 

How did you do it exactly ?

 

Best regards,

Melvin

Hi!

 

1. Opened the Layout file in Notepad++

2. Saved the file in other location as .txt

3. Made changes in Layout file

4. Saved my changes and closed the Layout.txt file

5. Removed the extension .txt from the file in the File Explorer.

6. Copied the file and pasted it in the Report folder in the report zip file

7. Changed the extension of the report file from .zip to .pbix

 

Regards

Fredrik

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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