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
Neehar
Helper I
Helper I

Apply Date Slicer Filter using C# SDK or Power BI Rest API for a Power BI Report

Hello Experts,

 

Is there any possibility to apply a date slicer filter using c# SDK or Power BI Rest API(not using Javascript) 

 

Neehar_0-1656430754323.png

 

My Requirement is to export power bi report to pdf in backend using c# SDK / Power BI Rest API by applying filter on DateSlicer and some other filters on tables.

So I want to know if this is possible, If Yes Please guide me on how to do that with some examples. 

I'm following the below article to export the file 

 

https://docs.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file

Here, we have an example to apply a filter on the Table column, but not on the Date Slicer.

 

I have tried many ways but nothing has worked.

 

Any help is highly appreciated.

 

 

Note: I'm able to export to Power Bi Report to PDF but not able to apply the filter.

 

Thank You 

 

 

3 REPLIES 3
Neehar
Helper I
Helper I

Hi @v-yiruan-msft, Thanks for the reply.

 I want to apply filters dynamically by passing different date ranges, So bookmarks won't satisfy my requirement.

 

Thanks | Neehar

Hi @Neehar ,

Please review the following links, and check if their methods can be used as an workaround.

How to set selected value from slicer to API in PowerBi

PowerBI does not work like a web development framework. You cannot "post" the selection in a slicer to an API.

I can think some options that could give an acceptable alternative:

  1. You import all the data from the API endpoint. Then use the slicer to slice as designed. For large amounts of data (in the API) there are techniques for paging that data in to PowerBI using M. Here is an example. PowerBI will handled gigabytes of data with ease although the API might not be up to the task.

  2. Use an intermediate database / datamart / datawarehouse to model the data and run your PowerBI on top of the datastore. With this approach you can use DirectQuery to limit the data you process through to PowerBI.

  3. If you are working locally and only using PowerBI desktop. You can set parameters in your PowerBI file and then supply the time through the parameters. If you save your PowerBI file as a PowerBI template (PBIT), then it saves your PowerBI without any data. When you open the template it will prompt you to supply the parameters.

Not quite a 100% answer but I hope it gives you some options to consider.


Making dynamic API call using a slicer/filter

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @Neehar ,

Using bookmarks you can export the report in a specific state, including configured filters, slicers, and other settings. You can refer the following links to get it.

Bookmarks

Export to file - Power BI Report with Filters / Parameters

The documentation currently states that the Bookmark name (whilst accepted as a parameter) is not currently available.
https://docs.microsoft.com/en-us/rest/api/power-bi/reports/exporttofile#pagebookmark

The only way to update output via bookmarks, is to pass in the bookmark state.
And the only way that you can get the bookmark state (that I know of) is via the JavaScript API. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Bookmarks#capture-and-get-a-current-view-as-a-b... 

The 'capture' function will return a single string value that represents the bookmark state. You can then pass this into the API.


Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.