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:
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.
To achieve navigation. Now we are going to change our measure again. This time by type Text with the original code. Looking like this:
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.
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.
Be the first to comment