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
gjwesteneng
New Member

Delete report, or dataset


My problem is that I want to be able to delete a report based on its ID. I've seen that it's possible to delete a dataset, which will subsequently delete the related reports. But when I have a report ID, how can I get to its dataset?

This is the complete story:

For a webpage we want to provide power bi reports to users. We create the power bi reports ourselves and then upload them to azure. For uploading the reports I used the C# code from MS sample project (PowerBI-embedded.sln - PovisionSample) as a basis.

We also want to add a description to a report and present to the user an overview of available reports, thus we decided to store the list of available reports in an MSSQL table. In this table we store a userfriendly name, a description and the ID of the report. That ID is used to retrieve the report when the user wants to see it.

To retrieve the report I call:
client.Reports.GetReportsAsync(_workspaceCollectionName, _workspaceId)


I then have all the reports in the the workspace. I use the one with the matching ID from the MSSQL table:
Report report = reportsResponse.Value.FirstOrDefault(r => r.Id == reportId);

This works without problem. But as said, the problem is when we delete a record in the MSSQL table containing the reports; we also want to delete the corresponding report in the workspace.

As far as I can see now I should also store the dataset ID in my SQL table, solely for the case if I want to delete the report. So my table needs the report ID for opening the power BI report and the dataset ID for removal, because I don't see how to get to the dataset with a report ID.......any suggestions?

Thanks and regards,
Gertjan

1 ACCEPTED SOLUTION

I found a possible solution in using the ID of the import class that was used when uploading:

// Import PBIX file from the file str
Import import = client.Imports.PostImportWithFile(_workspaceCollectionName, _workspaceId, file, datasetName);

 

This gives me an import.Id which I can store (instead of storing the report id like I do now).

When looking up the report I can lookup the import and find the report:

 

Import import = client.Imports.GetImportById(_workspaceCollectionName, _workspaceId, importId);
import.Reports[0].Id;

We deleting a report I can find the corresponding dataset:

Import import = client.Imports.GetImportById(_workspaceCollectionName, _workspaceId, importId);
import.Datasets[0].Id;

It looks like the imports are persited, at least for a couple of months, so I assume this should be ok.

View solution in original post

3 REPLIES 3
Eric_Zhang
Employee
Employee

@gjwesteneng

 

I don't find any API to get datasetId using reportId.

 

The thing I've noticed is that a dataset name are the same as a report name, so it might be one approach to get datasetId using reportName.

You can retrive the reports' names and IDs via 

client.Reports.GetReportsAsync(_workspaceCollectionName, _workspaceId)

You can retrive the datasets' names and IDs via below snappet in the Case '8' in ProvisionSample. 

 await ListDatasets(workspaceCollectionName, workspaceId);

Save both above to database tables and Join them on the column datasetName and reportName.

By the way, you will have  to use an extra parameter "Overwrite" to avoid duplicated dataset/report names when importing a pbix. 

 var import = await client.Imports.PostImportWithFileAsync
(workspaceCollectionName, workspaceId, fileStream, datasetName, "Overwrite");

 

Thanks for your suggestion!!

Unfortunately the dataset/report names are not unique, it's allowed to upload reports with the same name.

 

How can it be that there's no way to get a report's dataset or to get a dataset's reports??

I found a possible solution in using the ID of the import class that was used when uploading:

// Import PBIX file from the file str
Import import = client.Imports.PostImportWithFile(_workspaceCollectionName, _workspaceId, file, datasetName);

 

This gives me an import.Id which I can store (instead of storing the report id like I do now).

When looking up the report I can lookup the import and find the report:

 

Import import = client.Imports.GetImportById(_workspaceCollectionName, _workspaceId, importId);
import.Reports[0].Id;

We deleting a report I can find the corresponding dataset:

Import import = client.Imports.GetImportById(_workspaceCollectionName, _workspaceId, importId);
import.Datasets[0].Id;

It looks like the imports are persited, at least for a couple of months, so I assume this should be ok.

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.