Hello everyone,

I’ve noticed all of my previous blogs were about Tableau tips and tricks, however, recently I got to spend more time practicing Power BI. So in today’s blog, I want to share about something cool that I’ve learned, it is a quite new feature in Power BI called “Custom label”.

Supposed you have a chart as below and you can see the Sales value of Region by simply toggling the “Data labels” button. However, what if you also want to know the percentage of total for each Region?

If you go a little down further on the “Data labels” option, down at the bottom of the “Value” option, there’s an option for “Custom label”, toggle this on and we will be able to custom the label shown on the chart by inputting a field (if you can’t see this option, you will have to update your Power BI version).

Now I’ll show you two ways to show the labels, one is to show both number and the percentage at the same time, one is to dynamically switch between the labels by using parameter.

Show both labels

First of all, create 2 measures for “Total Sales” and “Sales Percentage” (I suppose you know how to create them). These will be used as a reference for our labels.

Next, create a new measure and type in the following DAX formula:

Labels =
FORMAT( [Total Sales] , “#,##0,.0K” ) &
” | ” &
FORMAT( [Sales Percentage] , “0.0%” )

For how to write the correct format within the quotation mark to meet with your requirements, you can refer for more here. Now, go to “Add data” in the “Custom label” and add in the “Labels” field that we’ve just created, you will get a bar chart with labels for both values and percentage.

Show labels dynamically

As we see the word “dynamically”, we immediately think of parameter (just like Tableau). This is what I put in my parameters:

Create a new measure with the following DAX formula:

Label switch =
SWITCH(
    SELECTEDVALUE( ‘Label Switch'[Label Switch Fields], [Total Sales]),
    NAMEOF([Total Sales]), FORMAT([Total Sales], “#,##0,.0K”),
    NAMEOF([Sales Percentage]), FORMAT([Sales Percentage], “0.0%”
    )
)
This formula basically means when we choose “Total Sales” on the parameter option, the label on the chart will be shown as the values of Total Sales, in the format specified. Same thing goes with the “Sales Percentage”. Now, go back to the “Custom label” option and input the new field “Label switch” that we’ve just created, then give it a try on your parameter, If you’ve done all the steps as instructed, you should get something like this:
Note: don’t forget to adjust your slicer to allow only single selection, otherwise if both options chosen, no labels will be shown up.
That’s all for my today’s blog. I hope you found it helpful.

 

 

 

The Data School
Author: The Data School