Creating histograms in Power BI

There are 2 ways to plot a histogram in Power BI – either use the custom histogram visualisation or bin the data beforehand and use a regular bar chart. Both have their advantages. I’ll create these to show the age profile of passengers on the Titanic using the popular dataset here

Here is the histogram.

The histogram is simple and quick to build and you can choose the bin width – or rather you can choose the number of bins and therefore the bin width indirectly once you know the range of the data. For example, the ages in this dataset range from 0 to 80 years – by choosing 16 bins, we get a bin width of 5 years.

We can see immediately that passengers in their twenties were the most popular group with corresponding fewer older passengers. There were also a large number of very young children.

To use the bar chart, we must first create a calculated column in the Query Editor for the bins. Let’s call it AgeBand and use a DAX formula like Number.IntegerDivide([Age], 5) to calculate it.
Add Custom Column - AgeBand
The drawback of this method is that it is slightly more complicated – we have to create this calculated column. If we want to change the bin width we must change the formula and re-load the data . However, the advantage of using a bar chart is that we can then put another category, such as Passenger Class on the legend to expand our analysis.

We can now see that older people were more likely to be in first class.