Power Query: ToolTip
16 September 2020
Welcome to our Power Query blog. This week, I look at how to use M metadata functions to create a ToolTip for columns.
I looked at some uses for metadata nearly three years ago in Customising Custom-Built Functions. One of the metadata functions I looked at was:
Documentation.FieldDescription as text
Description to show next to the display name.
As I described in that blog, these functions can be found at https://msdn.microsoft.com/library/mt807488.aspx.
Back then, when I looked at how Documentation.FieldDescription could be used, I was making a function I had created more user-friendly; this time, I will use it as I create a table.
I start by creating a new blank query. In Excel on the ‘Data’ tab, I choose ‘New Query’ and select ‘Blank Query’ from the dropdown next to ‘From Other Sources’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I can then access the ‘Advanced Editor’ from the Home tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
The M code I am going to use will create a simple table of employees.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
The M code I have created is:
let source =
#table({"Name", "Secret"}, {{"Mary Smith", "67"}}),
tableType =
type table[Name = Text.Type, Secret = Number.Type]
meta [
Documentation.FieldDescription =
[Name = "Full Name", Secret = "Age!"]
],
replaceType = Value.ReplaceType(source, tableType)
in
replaceType
In this M code, I first create a table by defining my source as an #table – for more on this, see Bring it to the Table. I then create a tableType, where I define the column properties of a table and include the Documentation.FieldDescription() function. Finally, I ensure my table uses that tableType (using Value.ReplaceType).
When I click ‘Done’, I get my table:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
If I hover over the title of Secret, I get a ToolTip:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I can see that the secret column holds Mary’s age (shhh).
There are some limitations to this. For example, if I remove Name:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
I find I can no longer see the ToolTip for Secret.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
This is because the table type has changed, so the link to the metadata is lost. If I delete this step, I can see the ToolTips again:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I can also lose the Tooltips on the table if I change the type of one of the columns:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/198/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I should therefore ensure that my tableType with metadata functionality is assigned to my table at a point where I am not planning to change anything that affects the tableType.
Come back next time for more ways to use Power Query!