Sub topic 8
Building your first visual
This chapter assumes you have installed Power BI Desktop, loaded a dataset with Get data, and can open Report view from the left-hand view switcher. It also assumes your data has a table named Sales with a numeric SalesAmount column and a text column such as Region or Category. If your column names differ, substitute them.
How a visual is built
A visual is a chart, table, or card on the report canvas. You build one by assigning fields to roles. A field is a column or measure shown in the Data pane. A role is a slot in the Visualizations pane, such as Axis, Values, or Legend.
Power BI turns the field assignments into a query against the data model. It then draws the result. This is why the same visual can change shape when you change a field or a filter.
Create a column chart
- Open Report view and select a blank area of the canvas.
- In the Data pane, expand the
Salestable. - Tick
SalesAmount. Power BI adds a visual, usually a clustered column chart with one bar. - Tick
Region. Power BI places it in the Axis role and splits the bar into one column per region.
You can also drag a field from the Data pane straight onto the canvas or onto a role in the Visualizations pane. Dragging gives you more control over which role receives the field.
Understand the summarization
When you tick SalesAmount, the Values role shows "Sum of SalesAmount". Power BI applied an implicit aggregation, a default calculation chosen from the column's summarization setting. Numeric columns usually default to Sum.
To change it, open the drop-down arrow beside the field in the Values role and choose Average, Count, Minimum, or another option. This changes only that visual. The column's default is set in Table view and is covered in the chapter on data types, formats, and summarization.
A measure gives you an explicit, reusable calculation. For example, this DAX expression defines a measure that you can drop into any visual:
Total Sales = SUM(Sales[SalesAmount])Measures are covered in a later chapter. For now, treat the implicit sum as equivalent.
Change the visual type
With the visual selected, click another icon in the Visualizations pane. Try a bar chart, a line chart, or a table. Power BI keeps the fields where it can and moves them to matching roles. A field that has no matching role may be dropped, so check the roles after switching.
Format and filter
The Visualizations pane has two tabs for the selected visual: Build visual and Format visual. Use Format visual to change titles, colors, and data labels.
The Filters pane lists the fields used by the visual. You can limit it to certain regions by expanding Region there and ticking only the values you want. This filter applies to this visual only unless you set it at page or report level.
Common errors
- A single tall bar and no breakdown: you added only the numeric field. Add a text or date field to the Axis role.
- Region shows as a sum or count: the field is in the Values role. Move it to Axis.
- The numbers look wrong: check the aggregation in the Values role. Sum, Average, and Count give very different results on the same column.
- A visual shows nothing after you change its type: a required role is empty. Reassign a field.
Exercise
You tick SalesAmount and Region in the Data pane, and the chart shows one bar per region. Which role does Region occupy, and how do you change the calculation applied to SalesAmount for this visual only?
Show answer
Region is in the Axis role. To change the calculation, open the drop-down arrow beside SalesAmount in the Values role and choose another aggregation, such as Average or Count. This affects only the selected visual.