Create dynamic reports for multiple values
To accommodate multiple values at a time, you first need to create a Microsoft Excel worksheet that has a table consisting of one column that contains the list of values.
Next, use the Get data feature in Power BI Desktop to connect to the data in that Excel worksheet, and then follow these steps:
On the Navigator window, select Edit to open the data in Power Query Editor, where you see a new query for the data table.
Rename the column in the table to something more descriptive.
Change the column data type to Text so that it matches the parameter type and you avoid data conversion problems.
In the query Properties section, change the name of the data source to something more descriptive. For this example, enter SalesPersonID.
Next, you need to create a function that passes the new SalesPersonID query into Query1:
Right-click Query1 and then select Create function.
Enter a name for the function and then select OK. Your new function appears in the Queries pane.
To ensure that Query1 doesn't show up in the field list for the report, which could potentially confuse users, you can disable it from loading in the report by right-clicking Query1 again and then selecting Enable load (selected by default) to disable the feature.
Select the SalesPersonID query that you loaded from the Excel worksheet and then, on the Add Column tab, select Invoke custom function to run the custom function that you created.
On the Invoke Custom Function window, select your function from the Function query list.
The New column name updates automatically and the table that contains the values that you're going to pass through the parameter is selected by default.
Select OK and, if necessary, run the native query. A new column for your GetSalesFromSalesPerson function appears next to the SalesPersonID column.
Select the two arrows icon in the new column header and then select the check boxes of the columns that you want to load. This section is where you determine the details that are available in the report for each value (sales person ID).
Clear the Use original column name as prefix check box at the bottom of the screen because you don't need to see a prefix with the column names in the report.
Select OK. You should be able to view the data for the columns that you selected, for each value (sales person ID). If necessary, you can add more values (sales people IDs) to the SalesPersonID column in the Excel worksheet, or you can change the existing values.
Save your changes and then return to Power Query Editor.
On the Home tab, select Refresh Preview, and then run the native query again (if necessary). You should see the sales from the new sales people IDs that you added into the worksheet.
Select Close and Apply to return to the report editor, where you see the new column names in the Fields pane.
Now, you can start building your report.
Comments
Post a Comment