Sub topic 8
Building your first visual
This chapter assumes you have installed Power BI Desktop, loaded a table with Get data, and can find the Report view on the left-hand view switcher. You should recognize the canvas, the Filters pane, the Visualizations pane, and the Data pane. Here you turn fields from the Data pane into a working visual and learn what Power BI does with them behind the scenes.
The examples use a Sales table with these columns: OrderID, OrderDate, Region, Product, Quantity, and SalesAmount. If your data differs, substitute your own columns of similar types.
What a visual is
A visual is a chart, table, card, or map placed on a report page. Each visual is a query over the data model. When you put fields into it, Power BI groups the data by the fields you chose and calculates a number for each group. Changing the fields changes the query, and the visual redraws.
Three terms matter here:
- A field is a column or measure shown in the Data pane.
- A category field is one you group by, such as
Region. - A value field is one you aggregate, such as
SalesAmount.
Two ways to start
You can start from a field or from a visual type.
- Tick the checkbox next to a field in the Data pane. Power BI creates a visual and picks a type for you.
- Click a visual type in the Visualizations pane first. This creates an empty visual. Then add fields to it.
Starting from fields is quicker. Starting from a visual type gives you control over the chart from the beginning.
Worked example: sales by region
Follow these steps on a blank report page.
- In the Data pane, expand the
Salestable. - Tick
SalesAmount. Power BI adds a column chart with a single bar. The bar shows the sum of every row. - Tick
Region. The single bar splits into one bar per region. - Select the visual by clicking its border or title area. Handles appear around it.
- In the Visualizations pane, click the bar chart icon (horizontal bars) to change the type. Horizontal bars suit long category names.
- Drag a corner handle to resize the visual. Drag the visual by its top edge to move it.
In the Visualizations pane, with the visual still selected, open the Build visual tab. You see field wells such as Y-axis, X-axis, Legend, and Values. The exact wells change with the visual type. Look at where Region and SalesAmount landed. For a bar chart, the category goes in the axis well and the number goes in the values well.
Field wells decide the meaning
Power BI placed each field for you based on its data type. You can place them yourself by dragging a field from the Data pane into a well. The well matters more than the order in which you added the field.
| Well | Role | Typical field |
|---|---|---|
| X-axis or Y-axis (category) | Groups the data | `Region`, `OrderDate` |
| Values | Gets aggregated | `SalesAmount`, `Quantity` |
| Legend | Splits each group into colored series | `Product` |
| Small multiples | Repeats the chart once per category | `Region` |
| Tooltips | Adds numbers to the hover popup | `Quantity` |
Try adding Product to the Legend well. Each bar is now stacked by product. Remove it by clicking the X beside it in the well. Removing a field from a well does not delete it from your data. It only changes the visual.
Aggregation: why the number is what it is
When you drop a numeric column into Values, Power BI aggregates it. The default is usually Sum. Click the arrow beside the field name in the Values well to see other choices, such as Average, Count, Minimum, and Maximum.
Summing is wrong for some columns. A UnitPrice column summed across rows has no useful meaning, and an average fits better. The default comes from the column's summarization property, which you can set in Table view. The earlier chapters on column properties explain that setting. In the visual, your choice in the well overrides the default for that visual only.
A column of numeric identifiers is a common trap. If OrderID is stored as a whole number, Power BI may offer to sum it. The total is meaningless. Set its summarization to Don't summarize, or use Count (Distinct) when you want the number of unique orders.
Using a measure instead
A column aggregated in a well is called an implicit measure. Power BI creates the calculation for you. An explicit measure is one you write in DAX, and it is the better choice once a report grows, because you define the logic once and reuse it everywhere.
To create one, select the Sales table in the Data pane, choose New measure on the ribbon, and enter:
Total Sales = SUM(Sales[SalesAmount])The measure appears in the Data pane with a calculator icon. Drag it into the Values well in place of the raw SalesAmount column. The chart looks the same, but now every visual that uses Total Sales shares one definition. If you later need to change the calculation, you edit it in one place.
A second measure counts orders:
Order Count = COUNTROWS(Sales)COUNTROWS counts the rows of the table it receives. It counts the rows that survive the current filters, so each bar shows the order lines for its own region.
Add Order Count to the Tooltips well. When you hover over a bar, the popup now shows both Total Sales and Order Count.
Formatting the visual
With the visual selected, open the Format visual tab in the Visualizations pane. It has two sub-tabs: Visual, which covers the chart itself, and General, which covers the title, size, position, and borders.
Useful first changes:
- Under General, open Title and edit the text to something specific, such as "Sales by region".
- Under Visual, turn on Data labels so each bar shows its value.
- Under Visual, open the value axis settings and set Display units to Thousands or Millions if the numbers are long.
- Under Visual, open Columns or Bars to change the color.
Use the search box at the top of the Format pane if you cannot find a setting. Formatting does not change the data. It only changes how the visual draws it.
Interacting with the visual
Visuals on the same page filter each other. Add a second visual: click empty canvas, tick Product and Quantity in the Data pane, and Power BI draws another chart. Now click a bar in the region chart. The second visual highlights or filters to show only that region. Click the bar again to clear the selection.
This is cross-filtering and cross-highlighting. The behavior depends on the relationships in the model and on the interaction settings on the page. To change how one visual affects another, select the source visual, open the Format tab on the ribbon, and choose Edit interactions. Small icons then appear above each other visual: Filter, Highlight, or None.
Filtering a single visual
The Filters pane has three scopes:
- Filters on this visual apply to the selected visual only.
- Filters on this page apply to every visual on the page.
- Filters on all pages apply across the report.
To show only the top three regions, select the visual, then in the Filters pane open the Region field, change the filter type to Top N, set Top to 3, drag Total Sales into By value, and select Apply filter.
Common errors
- The visual shows one huge bar or a single number. A category field is missing from the axis well. Add one.
- A text field appears in Values and shows a count. Power BI cannot sum text, so it counts instead. Check that the field you meant is numeric.
- The visual is blank. A filter may exclude all rows, or the field belongs to a table with no relationship to the others. Check the Filters pane, then Model view.
- A date column appears as a hierarchy of Year, Quarter, Month, and Day. This is the automatic date hierarchy. Click the arrow beside the field in the well and choose the plain date name to remove it.
- Totals look too large. The aggregation may be Sum on a column that repeats per row, such as a price. Switch to Average or write a measure.
Where this leads
You now have a visual that reads from the model, accepts fields in wells, and responds to filters. The next chapters inspect the data behind the visual in Table view and the links between tables in Model view. Both explain why a visual behaves the way it does.
Exercise
You tick OrderID (a whole number) in the Data pane and Power BI draws a single bar with a very large value. What happened, and how do you get the number of distinct orders instead?
Show answer
Power BI summed the identifier because the column is numeric. Summing order numbers has no meaning. Either set the column's summarization to Don't summarize in Table view and use the field with Count (Distinct) in the Values well, or write a measure such as Order Count = DISTINCTCOUNT(Sales[OrderID]).
Exercise
What is the difference between dragging SalesAmount into Values and dragging the Total Sales measure into Values? Why might you prefer the measure?
Show answer
The raw column creates an implicit measure that Power BI defines for that visual, using the column's default or chosen aggregation. The Total Sales measure is an explicit DAX measure with one shared definition. Prefer it because every visual that uses it stays consistent, and you can change the logic in one place.