Dynamic Column Selection using Power BI Parameters allows users to interactively choose which column of data they want to analyze or visualize by using what-if parameters or field parameters. This technique creates flexibility in reports by enabling users to change measures or dimensions shown in charts without modifying the report itself. to do this;
- Open your powerBI desktop and load the sample data set (default data set)
- Select the financials and load it
- The data will be previewed and it will appear under the data section at the right
- We will add a new table to create a measure that will get the sum of the columns sales, profit, discount and gross sales.
- To do this, click on enter data
- In the bar that will appear, rename it to measure and load
- It has been added to the data session. Click on the three dots on the measure and select new measure.
- Click on the new measure created and in the formula bar, write a formula for sum of sales and enter. That is, sales = SUM(financials(sales))
- You will see the measure name change to sales. Click on the three dots on column 1 above and in the bar that will appear, select delete from model. The table will now remain as a measure table.
- For profit, Click on the three dots on the measure and select new measure.
- Click on the new measure created and in the formula bar, write a formula for profit and enter. That is profit = SUM(financials(profit))
- For discount, Click on the three dots on the measure and select new measure.
- Click on the new measure created and in the formula bar, write a formula for profit and enter. That is discount = SUM(financials(discount))
- For gross sales, Click on the three dots on the measure and select new measure.
- Click on the new measure created and in the formula bar, write a formula for profit and enter. That is gross sales = SUM(financials(gross sales))
- After getting your measures into the measure table, we navigate to the modelling tab.
- Go to parameter, on the dropdown bar, click on fields parameter.
- Select measures and drag them into the Add and Reorder fields. Bring sales, profit, discount and gross sales and hit the create button. It will automatically add it to a powerbi slicer.
- Drag the slicer, go to build visual, select the middle tab.
- Click on the slicer settings, change the style to Tile and you will see our slicer displayed as tile.
- To get a stacked bar chart, click on the stacked bar chart in visualization
- We can be able to do sales, profit, discount and gross sales in one axis. To do this, click on parameter
- Go to table view, click on the eye icon on parameter and unhide it so that we can get the parameter field.
- Once you do that, it will appear in the report view.
- In the report view, drag the parameter field into the x axis
- In the data, go to the financials and select product, get it into the y axis. The sales, product, discount and gross sales are now in one axis.
- We can now select the names in the tiles to see each chart for sales, product, discount and gross sales.
- Add a conditional statement so that each category can display a different chart colour. To do this, click on the created stack bar chart, click on format visual and scroll down to the bars. Click on fx (conditional formatting)
- Go to what field should we base this on and select parameter
- Go to the section of if value is and edit the text to sales, select colour of your choice. In this example, we make use of the default colour, sky blue.
- Go to new rule to add another rule.
- If value is, edit the text to profit, select green colour
- Add new rule, if value is discount, select colour of your choice
- Add new rule, if value is gross sales, select colour and click on ok
- Navigate through and you will notice that the colours of the carious charts will change
Leave a Reply