question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set filter configuration for report

See original GitHub issue

Hi, my question is about configuring filters for the embedded reports.

Current behavior

The type of property filter in IEmbedConfiguration is filters?: models.IFilter[];, and IFilter itself is

export interface IFilter {
    $schema: string;
    target: IFilterGeneralTarget;
    filterType: FilterType;
    displaySettings?: IFilterDisplaySettings;
}

For configuring any report’s filter this set of property is not enough.

Expected behavior

For example for the basic type of filter, the set of properties is

export interface IBasicFilter extends IFilter {
    operator: BasicFilterOperators;
    values: (string | number | boolean)[];
    requireSingleSelection?: boolean;
}

So I would expect to have IReportLoadConfiguration where filters?: ReportLevelFilters[]; and

ReportLevelFilters = IBasicFilter | IBasicFilterWithKeys | IAdvancedFilter | IRelativeDateFilter | ITupleFilter | IRelativeTimeFilter.

Can you advise me on how to set filters properly for reports?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
WeslleyBorgescommented, Oct 1, 2021

@harishv6665

  1. If you are using TypeScript, then you can put @ts-ignore like this:
<PowerBIEmbed
	embedConfig={{
		...embedConfig,
		type: "report",
		tokenType: models.TokenType.Embed,
                // @ts-ignore 
		filters: [{
				$schema: "http://powerbi.com/product/schema#basic",
				target: {
				table: "TABLE_NAME",
				column: "COLUMN_NAME"
				},
				operator: "Is",
				values: "XYZ"
			}]
	}}
/>
  1. Check out the docs for Constructing Filters to verify your filter array.

You are just a god, bro. Thank you so much.

2reactions
NazarKryvyycommented, Jan 7, 2021

@harishv6665 There are 3 levels of applying filters: Report, Page, Visual. Most time you would work with the visuals.

To get visual:

  1. Find an active page.
  2. Request all visuals on this page
  3. Search for the visual you need.

Then you can set filter and slicerState for visual. Filters are for filtering data in your visual, e.g. you have a year picker and it has 3 available yers to choose 2020, 2019, and 2018. If a filter with value 2020 is set for year picker visual, “2020” would be the only option that remains in it. If you want just to choose a value in it use setSlicerState(filterConfig) instead of setFilter(filterConfig).

After receiving the expected visual, request it slicer state with await visual?.getSlicerState() and check a target property to get the propper table name. In my case, it differs from what I see in UI. Then you can properly configure a filter for your slicer.

One more tip, you can also manually configure any visual then request its slicerState and check what filter configuration is using in this visual.

Use this wiki for more info.

const monthFilterConfig = {
    $schema: "http://powerbi.com/product/schema#basic",
    filterType: 1,
    target: {
        table: "TableName", // table name you can get from visual entity
        column: "Month"
    },
    operator: "In", // FYI "Is" is not acceptable, check BasicFilterOperators
    values: [momet().format("MMMM")],
    requireSingleSelection: false
}

const PowerBIReport = () => {
  const [report, setReport] = useState<Report>();

  const setFilterForVisual= async () => {
        const pages = await report?.getPages();
        const activePage = pages?.filter(function(page) {
            return page.isActive;
        })[0];
        if (activePage) {
            const visuals = await activePage.getVisuals();
            const monthVisual = visuals.find((item)=>visual.title === "Month")
            await monthVisual.setSlicerState({ filters: [monthFilterConfig] });            
        }
    };
  
  return (
    <PowerBIEmbed
         embedConfig={sampleReportConfig}
         eventHandlers={eventHandlersMap}
         getEmbeddedComponent={(embedObject) => {
           setReport(embedObject as Report);
         }}
     />
  )
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring filters in reports - HighBond
Add a filter to a report · Open the Reports app. The Browse page opens. · Open a report and navigate to the...
Read more >
Format filters in Power BI reports - Microsoft Learn
Go to File > Options and settings > Options > Query reduction. Select Add a single Apply button to the filter pane to...
Read more >
Add Advanced Filter Configuration for a Report Entry in ...
You can enable advanced filters (pv values) in reports using Solution Manager. To enable advanced filter configuration in a report: Click Advanced Filter...
Read more >
Set Report Filters - Firewall Analyzer - ManageEngine
Set Report Filters - Firewall Analyzer. Include filters specify those criteria which the log data must meet in order to be included in...
Read more >
Create, edit, and manage filters - Looker Studio Help
To create a copy of the filter, click Duplicate in the Actions column. You can then modify the filter conditions and apply it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found