Forum Discussion

automation's avatar
automation
Frequent Visitor
1 year ago

how to filter the publish to web report using query string filter?

Hello Experts,

 

 

I've gone through this post: Link

 

I am not sure how this filter works on a publish-to-web URL with a query string for

 

How are these country filters working on publishing to web links?

How can I achieve this?

 

 

 

It's mentioned in the official documentation that:

Query string filtering doesn't work with Publish to web

 

 

 

How can a user achieve query string parameter report filters using the "Publish to Web" URL?

Can someone explain how the above URLs function with the Country filter included in the URL? How can I implement this functionality?

 

I have the same requirements for my clients. Could you please guide me on how I can achieve this?

My client is not willing to invest in purchasing an embedding license. We plan to use a single Power BI Pro license and leverage the filter options demonstrated in the URLs above, which include filters for three different countries.

9 Replies

  • Hi automation 

     

    As you have mentioned in your question, query string thought print is not available in publish to web, and there is no work around for this. Unfortunately, you will either have to use power BI embedded or get power BI licensing. If you are looking to use the very string filtering in the url.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, automation 

    First of all, thank you for your question! Regarding the URL filter you mentioned, its working principle is to pass the query parameters to the filter panel to achieve report filtering. The specific format is as follows:

     

    reportId=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx&pageName=ReportSection&filter=Table/Field eq 'value'

     

    reportId: Identify your report.
    pageName: Specify a page in the report.
    Table/Field: Correspond to your table name and field name respectively.

    Ultimately, this URL will pass the value to the field in the specified table, forming a page filter. As shown in the figure below, I have disassembled it:

    Next, as to why "Publish to Web" does not have this function: when we publish the report to the Web, the report ID and page will be encrypted and converted, and the published report does not have a filter panel, so these values ​​​​cannot be passed to the corresponding fields.

    You mentioned that you have a Pro license and your users are covered by Pro per user licenses. Actually, you don't need to publish the report to the web, you can implement report filtering by simply adding the following suffix to the report URL:

     

    ?filter=TableName/ColumnName eq 'value'

     

    The example is shown in the following figure:

     

    Here are the results:

    In your case, just replace it with the corresponding country table/field. Finally, you should apply it directly behind the link to your Power BI report instead of publishing it to the web, which not only creates security issues, but also leaves a lot of functionality unsupported.

     

     

    Best Regards

    Jianpeng Li

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

     

     

     

     

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, automation 

    As you mentioned, the idea of implementing post-"publish to web" slicer filtering via JavaScript is very clear. Here are the brief steps to achieve it:

    1. First, publish the report on the web.

     

    2. Open the developer tools in your browser, which can usually be opened by right-clicking on the page and selecting "Inspect" or pressing F12.

    3. In the console, you can find the HTML tag of the slicer, usually the slicerItemContainer.

     

    4. Achieve the selected state by controlling the aria-selected attribute. You can get that tag using the getElementsByClassName method in JavaScript.

    Document: getElementsByClassName() method - Web APIs | MDN

    5. Use the setAttribute method to set the value of the aria-selected attribute to implement the filtering function of the slicer.

    Element: setAttribute() method - Web APIs | MDN

    This approach is beyond the scope of Power BI support. You should implement this according to your development department.

     

     

    Best Regards

    Jianpeng Li

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

  • automation's avatar
    automation
    Frequent Visitor

    Anonymous& GilbertQ 

     

    I understand the official documentation states that passing query string filters in a public URL for Power BI is not supported.

    However, how are the URLs below functioning?

    I would like to use a similar approach for my requirements. Could you please provide a more detailed explanation of the JavaScript steps involved?

     

     

    Anonymous 

    I'm not an expert in JavaScript, but with the help of ChatGPT, I could write the following code. However, I do not see the filter being applied to the report as expected.

     

    Not sure about this URL he is not using the JS approach:

    Applying the filter `&Country=France` directly in the URL works for this user. I'm not sure how we can achieve the same result.

     

    https://app.powerbi.com/view?r=eyJrIjoiZTA5N2VkYWQtYmNiMS00YWFmLWEwZWQtOGY4MmExNTlmZjllIiwidCI6ImMyOGQyZTEyLTA5ODgtNGFjZi1iZGJhLTExOTU4MmU4ZDA4ZCIsImMiOjl9&Country=Italy

     

    https://app.powerbi.com/view?r=eyJrIjoiZTA5N2VkYWQtYmNiMS00YWFmLWEwZWQtOGY4MmExNTlmZjllIiwidCI6ImMyOGQyZTEyLTA5ODgtNGFjZi1iZGJhLTExOTU4MmU4ZDA4ZCIsImMiOjl9&Country=France

    below is my code:

     

    <!DOCTYPE html>
    <html>
    <body>
        <h1>My Power BI Report</h1>
        <object 
            data="https://app.powerbi.com/view?r=eyJrIjoiOGUwZWNmYjktZTc2Zi00MWIzLTk5NzktMjZmMjY3ZDIwMjQyIiwidCI6ImE2OTI0YWVjLTI1N2EtNDkzZi04ZDUyLTM1ZDA1MzdiMTc3NiIsImMiOjZ9&pageName=67c0b6533c0b91c3888e" 
            width="600" 
            height="400">
        </object>
    	<script>
    		// Wait for the page to fully load
    			document.addEventListener('DOMContentLoaded', function () {
    				// Find the element with data-row-index="2"
    				var targetElement = document.querySelector('[data-row-index="2"] .slicerCheckbox');
    				
    				if (targetElement) {
    					// Update the aria-selected attribute to "true"
    					targetElement.closest('.slicerItemContainer').setAttribute('aria-selected', 'true');
    					
    					// Update the class to include "selected"
    					targetElement.classList.add('selected');
    				}
    			});
    
    	</script>
    </body>
    </html>