Build a TOGGLE BUTTON Like a PRO in Power BI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you want to build a toggle button that lets you switch between two stains well the solution might not be as straightforward as you might expect it to be because any solution that you find on the internet either enforce custom visuals or overlapping images or buttons that you then switch in between bookmarks but can we also just do it with one native button well of course you can let me show you how [Applause] welcome to how to power bi my name is boss and if this is the very first time for you visiting this channel then make sure to hit that subscribe button to stay up to date on all of my videos in which I share everything I know about power bi now let's dive in straight away and see how we can build a talk about it now the toggle button lets us switch between two states that we can capture with bookmarks so let's start by first adding a bookmark okay so let's go here to the top to view and then we go to bookmarks I open the bookmarks panel now here we can simply click on that and we have our first bookmark and this first bookmark is going to be for our toggle on state all right and then later on WE of course also need a bookmark for tokolov so let's create that one as well straight away so over here double click and then rename it to toggle off okay so now we have two bookmarks now the next thing that we can do is insert a bookmark Navigator so if we go here to insert then buttons and then here we have the Navigator buttons and here at the bottom we find bookmark Navigator and here we have our Navigator with two buttons one for the onset and one for the off State however with a real toggle it shouldn't matter where you click on that button the state should change and here it does matter where you click so therefore we cannot do it with two buttons we should actually have only one button showing here now how can we achieve that let's go to the formatting options for the bookmark Navigator and then all the way down to bookmarks and from this drop down we can choose the bookmarks for which we want to have buttons in the bookmark Navigator however it just says all well how can we then choose here just a few of the bookmarks that we need for this Navigator because for our purposes we just need one well for that we need to work with groups so let's go here to the bookmarks panel and then here for toggle on I want to place it in a separate group you see it's grayed out you first have to click on the toggle on bookmark then click on the three dots and you see now we can click and group all right so we place this bookmark in a separate group so over here we can rename that group to let's say toggle and now that we place the toggle on bookmark in a separate group we can go back to the formatting options and then bookmarks and then here from the drop down there you see we have now the toggle group now sometimes this group doesn't show up straight away in the drop down then just hide the panel show the panel and then it should show if it still doesn't show insert a new bookmark Navigator and it will be there now let's click here on the toggle group and then here also make sure to allow deselection and here we want to launch on this selection toggle off so that we have the two states toggle on where we collect the button for the first time and then when we click the button same button second time then well the bookmark toggle off gets triggered so the most important part for this toggle button is actually already done it letters toggle between two states however it doesn't really look like a toggle button just yet we need this little circle that jumps from the left to the right and the other way around now how can we achieve that well for that we need to go back over here on the right hand side now the first thing that I want to change here is that what shows on the button is not that the text toggle on but the circle now what shows on the button is determined by The Bookmark name so let's go to the bookmark name and instead of toggle on we're going to replace this we have a unicorn character that looks like a circle and where can you find it well just do a simple Google search and it gets you to websites like this one and here I have a character that I like I'm gonna copy over but of course you can be creative and also try out different characters but for this one let's first start off with a normal Circle I'm going to copy it over and I'm going to rename toggle on to well good Circle that's it you see now on the button we have a little circle popping up well the next thing that we can do is play around with the formatting so let's go here to format style and here we have all these different states now just make sure that you start with the default State and for the default State I want to have that Circle well a little bit bigger so let's increase the size to maybe 26 and then I want that Circle to be on the left hand side so here for the horizontal alignment choose to the left and the next thing that we need to do is to well change the shape the overall shape of the button so let's go into shape and then choose something different you can go for Bell or rounded rectangle and then here the rounded Corners I'm just gonna put up to let's say 50 and then we can also change the overall size so let's go to General properties and then here for the height let's go for 75 and the width 125. now in reality I probably would go a little bit smaller than this however I want you to see exactly what I'm doing so I make this toggle just a bit bigger than usual all right now let's go back to the visual formatting options over here and then again go here to style and then we go all the way down and we go to border and by adding a border here we can squeeze the rest of the visualization so that comes closer to the circle now let me show you what I mean if we put here a width of let's say done you see we get the black area in the back a little bit smaller and we just keep on going up and up until the top and the bottom are a little bit above and below the circle okay so here I'm going to put it to let's say 80. but while we are doing this you see that the circle goes outside of the black area behind it which is not what we want we want to keep it inside so to push it back in we can go here to text and then here make sure horizontal alignment is to the left and then we add a little bit of padding for example we can add let's say a panning of time you see jumps back in now you see also that the circle might not be perfectly centered in the middle so we have to push it a little bit up so let's put a little bit padding from the bottom for example five or maybe four so just playing around with it until it looks good like this and that's it I see if we have now something that looks much more like a double button however we're not entirely there just yet we have to make sure that it looks good in every state with the colors that we want okay now here for the default State I want to go maybe for grain all right so I'm going to choose a different fill color and choose a light gray and then here for the Border we leave it to White that's important okay and then we go to a different state so I'm going to switch it to select it and then for the selected State we want to have maybe a green color so let's go into fill open this up and go for green now here for the selected State you see the Border still white okay and then for the text well we want to have the horizontal align to the right then we have to change the padding of course so on the left hand side it's going to be zero and now we're going to put the 10 pixels on the right hand side the same as we had before on the left hand side okay good so we have now all the formatting options for the selected State and that's it let's try it out let's go here to the button hold the Ctrl key click on it and this is how it looks like in the default State and you see our Circle change to Black which is actually not what I wanted to have so let's just go back to the formatting options change over here this state to default and then here you see for the font color somehow I accidentally chose black well that needs to be white okay now let's try it again let's hold the Ctrl key click on it now it's on now it's off on off on off perfect we have our toggle so once you have your toggle of course you want to connect it with some kind of functionality where you have two states that you capture with a bookmark okay now let's just try one example I'm going to copy this over to a different page where I already created this chart over here and here you see the sales for different channels using the small multiples feature and what I want to do is switch between two stains and one of them is relatively new from the November 22 version so let's try that one out and let's go into formatting and then y-axis and then here you see scale to fit that one is new now before it was always the case that at the y-axis is in sync between all of the small multiples however now they can also get their own y-axis like this and scale them differently from one another okay and I want to have the ability to switch back and forth however here I can only do that as the developer the end user cannot do that fridge is of course very annoying so we can use however bookmarks to switch between two visualizations one where we have scale to fit on and one way we don't have that okay so let's try that out okay so let's build that I'm going to turn for the first one skill to fit off so that's this one and right next to it I still have to paste that toggle button that we created before for now I'm just gonna put it here and there top right corner okay now the next thing that I'm gonna do is I'm going to take the visual Ctrl C and then click somewhere else Ctrl V to base so we have two overlapping visuals as you see now then what also helps us is if we go into view selection then here you see we have two types total sales and we have the bookmark Navigator The Bookmark navigator at the end needs to overlap the other two visualizations that's important and the two visualizations that we have here we just need to make sure that they're nicely aligned so applying to the left and align to the top perfect and of course they already had the same dimensions now the next thing that we need to do is take one of them let's take this one here then go to formatting and then here we can go to the y-axis and make sure that scale to fit is on okay so for one and Zone and for the other one it's off okay and now we just need to hide one of them so let's I this one over here and see now the y-axis are synced and with the other one the y-axis are not six so let's say this needs to be my total off State and when I turn it on then the axis gets it okay now to capture that state we need the bookmarks that we created before we just need to update them so let's go hit the bookmark section and here you need to make sure that you have the check marks in front of the right places so first of all we don't need to capture the data state so that's what I'm going to turn off then the current page we also don't need and here select the visuals I want to have it for and that's basically it so you see over here we have now only check mark for display and selected visuals okay now then for toggle off we're going to do exactly the same so no check mark for data no check mark for current page and a check mark for selected visuals okay and that's it so now we have exactly the same for the two bookmarks however then we still need to update them which we can do by using that selection pane only select those visualizations then we go here to The Bookmark and here you see I switch to talk on and then I want to show the other one so I want to show this state both are selected go to the toggle on bookmark subject okay and then we switch the other way around so I'm going to show the other one now we have the axis not in sync and here for the bookmark navigator that one needs to be there enough then right so I need that other state then again make sure that all three are selected go to toggle off and update the bookmark okay and then try them out click on the toggle on bookmark looks like this click on the toggle off bookmark looks like this and that's it all right and now we can also try it from the report so hold the control key click on your toggle button toggle on dog enough dog alone so we did it we created a toggle button with just one normal native button instead of overlapping images overlapping buttons or using custom visualizations and now it's time to get creative and start playing around with the Unicorn character and the different formatting options that we used and come up with something like this or this now let me know what you came up with and share it in the comment section below now if you like that last example to switch between synced and not synced axes but you don't want to have these overlapping visualizations well then check out this video over here if you want to dive in a little bit deeper into the whole design topic then check out this video here and if you have any questions just share it in the comment section below I want to thank you for watching and see you in the next video
Info
Channel: How to Power BI
Views: 155,015
Rating: undefined out of 5
Keywords: howtopowerbi, datatraining.io, bas dohmen, power bi, powerbi, toggle button power bi, toggle button, toggle, toggle power bi, bookmark navigator, custom buttons power bi, unichar, on off button powerbi, switch button power bi
Id: 5QMpc5fUV2I
Channel Id: undefined
Length: 14min 6sec (846 seconds)
Published: Sun Dec 11 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.