Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

ibarrau

[PowerBi][UX] A Single Measure for Formatting and Button Navigation

After working a lot with buttons one begins to notice certain specific details. In this case we are going to talk about the navigation between pages and format of a button. For those who didn't know, Power Bi allows us to use measurements as functions in different format options. Among them we will see that we can navigate between pages by placing as an action of a "Page Navigation" button a measure that returns the exact name text of the page. The measurements also allow us to play with the colors. The result of both numerical and text measurement can help us determine color rules for button states (default, on hover, click).

What usually happens is that when working with colors we choose whole type returns to make color rules or hexadecimal directly to paint them as text. When we want to navigate we need the text of the page. What we are going to see next is how to combine that measure for a binary result (two options). In our case we want to paint a button as "disabled" and at the same time it cannot navigate with a single measure.

NOTE: The following example will be a mere test of functionality, it does not necessarily give a strategic business sense.

 

Example: Our report contains a product analysis according to a specific category. So to be able to analyze it better without errors, it is necessary that only 1 category is selected at the time of browsing (the filter is synchronized in both pages but only in one visible)

Let's look at our menu:

ibarrau_11-1663274831716.png

The behavior is simple. If we select the category "Home Appliences" "View Home Sales Analysis" will be enabled, but if any other category is selected, "View Product Sales Analysis" will remain. Let's assume that this category is so large and different that it is disruptive for our normal analysis and needs special measures next to a page of its own.

Messageless method

To control the navigation we would normally do something like this:

 

 

 

Format Navigation Home =
VAR __selectedCategory = SELECTEDVALUE(ProductCategory[Category])
RETURN
IF (
   __selectedCategory = "Home Appliances”,
   "HomeSalesAnalisis"
   , BLANK()
)

 

 

 

We determine the selected value and the answer in case we have the desired selection will be the text of the page name. Normally then we would proceed to create another measure to paint the button, but no. Let's look at the following:

The new version of Power Bi Desktop will be able to recognize the type of data that a measure returns. Not like before I categorized. That measure will only return text and we cannot change it. This means that the measure could not be used within the conditional formatting "Rules". What we will do is manipulate the measure to deceive Power Bi and think that it can return number to allow us to paint our measurement when the result is white to be able to use it both in navigation and format. Let's see how it would look:

 

 

 

Format Navigation Home =
VAR __selectedCategory = SELECTEDVALUE(ProductCategory[Category])
RETURN
IF ( 1 = 1,
   IF (
       __selectedCategory = “Home Appliances”,
       "HomeSalesAnalisis"
       , BLANK()
   ), 1
)

 

 

 

By creating an IMPOSSIBLE condition that returns false, we will make the false return number and trick the engine. This will allow us to define that the measure is a number.

ibarrau_10-1663274820132.png

Now we can determine a function for our conditional formatting:

ibarrau_2-1663274623512.png

The Rules of the format are only applicable to numeric values. For this reason we had to trick the engine to carry out our process. The irony is that there is a condition that could be applied against text that is "Is Blank". We are going to feed on it to control if the result is not correct and thus paint the button as disabled.

To achieve navigation. Now we are going to change our measure again. This time by type Text with the original code. Looking like this:

ibarrau_3-1663274623513.png

Now let's configure the navigation:

ibarrau_4-1663274623514.png

Finally the process of our button would be complete. Painted when disabled and not performing any action but selecting Home Appliences activates and allows navigation. Let's see in action:

ibarrau_5-1663274623516.gif

Method with message

For the other button that would be on for everyone except Home Appliances we are going to perform a slightly different method that does not need type changes but instead of not performing an action when it is disabled, it will return an error popup. This may be attractive to some from an experience point of view and negative to others. The truth is that the solution is simpler. In order not to change the type and that both are text, we need the color code because it is the only way that a text is valid for conditional formatting. Let's look at the method for the other button:

 

 

 

Format Navigation =
VAR __selectedCategory = SELECTEDVALUE(ProductCategory[Category])
RETURN
   IF (
       __selectedCategory <> “Home Appliances”,
       "ProductSalesAnalisis"
       , “#808080”
   )

 

 

 

Since before the white result helped us to paint, we could directly put the code of the desired gray color. The way in which PowerBi reads text to paint colors is simple, if it has rgb or hexa it interprets it and if not it fails and does not paint.

ibarrau_6-1663274623517.png

The same will happen when browsing, if it is true it will navigate to the ProductSalesAnalisis page and the false will go to a text on a page that does not exist.

ibarrau_7-1663274623519.png

The difference with the previous one is that navigating to BLANK() the engine does nothing, but navigating to a text that is not a page will produce an error message:

ibarrau_8-1663274623519.png

Let's look at the second option in action:

ibarrau_9-1663274623521.gif

We reached the end of the post and could see two ways to use a single measurement and control the conditional color formatting of a button according to the action as well as the navigation of the page.

I hope this will help them control the navigation of their pages by reusing measures to support a simpler model. As always you can find this development on my github.

Original post in spanish here.