Create dynamic reports for individual values
To create a dynamic report, you first need to write your SQL query. Then use the Get data feature in Power BI Desktop to connect to the database.
In this example, you connect to your database on SQL Server by following these steps:
After you have entered your server details, in the SQL Server database window, select Advanced options.
Paste the SQL query into the SQL statement box and then select OK. When the connection is made, the data is shown in the preview window.
Select Edit to open the data in Power Query Editor.
Next, you create the parameter by following these steps:
On the Home tab, select Manage parameters > New parameter.
On the Parameters window, change the default parameter name to something more descriptive so that its purpose is clear. In this case, you change the name to SalesPerson.
Select Text from the Type list and then select Any value from the Suggested value list.
Select OK. A new query is shown for the parameter that you created.
Now, you need to adjust the code in SQL query to assess your new parameter:
Right-click Query1 and then select Advanced editor.
Replace the existing value in the execute statement with an ampersand (&) followed by your parameter name (SalesPerson), as illustrated in the following image.
Make sure that no errors are shown at bottom of the window and then select Done.
Though you don't see a difference on the screen, Power BI ran the query.
To confirm that the query was run, you can run a test by selecting the parameter query and entering a new value in the Current Value box.
A warning icon might display next to the query. If so, select that query to view the warning message, which states that permission is required to run this native database query. Select Edit Permission and then select Run. When the query runs successfully, the parameter displays the new value.
Select Close and Apply to return to the report editor.
Now, you can apply the parameter to the report:
Select Edit queries > Edit parameters.
On the Edit Parameters window, enter a new value and then select OK.
Select Apply changes and then run the native query again.
Now, when you view the data, you see the data for the new value that was passed through the parameter.
Comments
Post a Comment