Five must-know #hacks in Power BI — Part 3

Enridge
6 min readAug 21, 2023

--

  1. Custom colors on a chart visual — apply color formatting to a chart
  2. Custom sort on a visual — sort a column based on another column
  3. Modify data in a custom table — re-edit a custom table
  4. Multi-sort on a table visual — sort a visual based on multiple columns
  5. Copy table — export full table out of Power BI
Photo by Isaac Smith on Unsplash

1. How to apply auto coloring on a visual

If in case you want to apply multiple colors to a bar chart, you will have to navigate to the Columns section of the visual formatting blade and then go to Colors properties and turn on Show all to set colors to each bar individually.

Bar chart colors

This isn’t an effective method. There are three ways to automate this. The first approach is a quick one (although I don’t often recommend it).

1. Add the same field that’s on X-axis to Legend (in this example “Awarded Type”) to automatically set different colors for each bar. But the drawback is that you cannot use Legend for any other field. If you can forgo legend, you can opt for this approach.

Bar chart colors

Two other things to be taken care of in this method - select “Stacked column chart” instead of “Clustered column chart” and turn off the Legend.

Multi-color bar chart

2. Create a DAX column on the “Opportunites” table by defining color codes for each “Awarded Type”

Awarded Type Color = 
SWITCH(Opportunities[Awarded Type]
,"Renewal","#DB6917"
,"New Business","#F4D407"
,"Additional Business","#8EBA43")

Now go to the bar chart and click on the fx icon under the color properties. In the following dialog box select the newly created DAX column that has all color codes.

Finally, the bar chart will be colored based on the codes provided in the DAX column.

Multi-color bar chart

3. The third approach is to save the same color codes in a custom table instead of a DAX column.

Custom table with color codes

After adding the table, create a relation between this new table and the main table “Opportunities”, using the common column, “Awarded Type”. You can do this by dragging and dropping the field from one table into another table.

Table relationships

Make sure that you select Both for Cross filter direction on the relationship properties. You can set this property by double-clicking on the relationship line.

Relationship properties

Now go to the bar chart and repeat the same step you did in method 2

Expression for bar color

2. How to apply custom sorting on a visual

Generally, the default sort applied on visual is a dictionary/alphabetic sort, which sometimes may not be useful for us.

Sorting on visual

For example, in the visual above, I want to sort the x-axis based on a user-defined order, Discovery-> Qualifying ->Proposal->Negotiation instead of the default dictionary sort. In such a case, we must define the sorting order using a custom table.

Custom table with sort sequence

After adding the custom table, create a relationship between the “Opportunities” table and the “Status Order” table using the “Status” column.

Table relationship

Now, go to the data view and add a DAX column “Status Order” to the main table “Opportunites”. We must do this as the sort feature needs the order column to be in the main table where the original “Status” column is present.

Adding dax column
Status Order = RELATED('Status Order'[Order])

Finally, select the “Status” column in the “Opportunities” table, click on the Sort icon in the Home menu, and then select the newly added DAX column “Status Order”. This will sort the x-axis as per the order we defined in the custom table.

Set secondary sort column

3. How to modify data in a custom table

After you are done creating a custom table, you will notice that you cannot edit it in the data view. You see a read-only view, so if you need to make any modifications to the data or add new data, you must go to the Power Query editor.

Table View — Read-only

To open Power Query, navigate to the Home tab and click on the Power Query editor icon.

Power Query — Launch Button

On the Power Query editor select the custom table and click on Source settings

Power Query Editor

This will open up the custom table in edit mode so you can modify or enter new records.

Custom table in edit mode

Click OK to go back to the Power Query editor and click on close and apply to apply the changes to the Power BI desktop.

Power Query Editor — Close & Apply

As you can see, a new record is added to the custom table “Status Order”

Power BI Desktop — Table View

4. How to apply multi-sort on a visual

This Power BI tip might seem very basic, but until I knew it, I struggled with it myself. Sorting a table using multiple columns is something we often need to do while presenting data in a flat report. To achieve this on a table visual, just hold the Shift key and click on the column(s) you want to sort by. Click twice on the same column to toggle between ascending and descending sort.

Table Visual

Shift+Click doesn’t work in a Matrix visual, but if you want to apply multi-sorting, here’s a workaround. Start by creating it as a table visual, apply the multi-sort, and then convert it to a Matrix. The sort order will persist even after flipping the Table into a Matrix visual.

5. How to copy an entire table

All visuals in Power BI provide an option to Export data out of Power BI. You can add the required fields to a table visually and then export them to a file.

Table visual — Export data

Alternatively, you have the option to copy the entire table. This option is not visible on the report view.

Report View

For this, you have to navigate to table view and then right-click on the table you want to copy to see the Copy table option.

Table View

For more hacks please read…

Useful, they may be. Sample files, download from here, you can!

For more stories, follow you should! -Yoda.

--

--

Enridge

Data-driven innovations with expertise in data engineering, solution architecture and analytics.