Burning Questions: How to Add a Monthly/YTD Switch to a Power BI Dashboard?

One of the questions we get most often by our users is how to create a switch in their Power BI dashboard that would let them switch between Monthly and YTD views. You can do this by using Data Analysis Expressions (DAX), which is the formula language used throughout Power BI. This blog post will provide a quick overview of what you need to do to create a simple switch.

Before you start, download the examples from our webinar page for Top 5 DAX tricks for super effective Power BI dashboards. We also recommend that you watch the video as it also contains detailed step-by-step instructions for preparing your data and tables that are not covered in this post.

Start by opening the Sales Dashboard example (SalesDashboard-ZebraBI-webinar.pbix) from the zip file you downloaded. Open a new page by clicking on the + icon on the bottom of the start page.

The example already includes all the tables, relationships between them and code, so you just need to recreate the basic sales dashboard you will add the Monthly/YTD switch to.

Recreating the basic visualization

Start by recreating the main visual in your report. Add a Zebra BI Power Chart and select the following fields: Group under Business Units, Month under Calendar, AC and Revenue PY under Sales. Set them to the corresponding Fields as shown on the image below:

Now combine various visuals. For example, you can add a comparison to previous year using another dimension. Add a Power Table and select the fields as shown:

This table adds a comparison of actual results to the revenues from the previous year by individual product groups and divisions.

This visual is fully responsive and also controls the small multiples visual on the right that you've created in the previous step. If you click on a category, the chart on the right will change to display just the selected category or group of categories (division). With this, you've already created a great visual. However, we can make it better.

Adding slicers to your dashboard

Next stop is adding two slicers: Year and Month that you can use to switch between views for individual months and years.

Click on Year field in the Calendar group and drag and drop it onto the dashboard. Switch it to the Slicer visualization and select Dropdown option from the menu.

Add another slicer for months. Click on Month field in the Calendar group and drag and drop it onto the dashboard. Switch it to the Slicer visualization and again select the Dropdown menu item.

This will break your visualization. To fix it, you need to decouple the time series view from your slicer. Click on the month slicer and select the Format tab on your ribbon. Select the Edit interactions tool.

This shows additional controls on the dashboard, where you can control what impact the selected visualization should have on the others. To prevent the currently selected visualization element from impacting your small multiples chart, you should select the no impact icon.

Adding the Monthly/YTD switch to your dashboard

Now, we will add the Monthly/YTD Switch. Switch to Data view and add another table for the switch on the  dashboard. Go to the Relationship view, where you will create what is called a "disconnected table" and serves as a switch between two values. Click the Enter Data button in the Home tab and name it Period Calculation in the Name field on the next screen.

You need to create just two columns - Period calculation and CalcID. 

You now have a new table in your project that is available for you to select in Report view in Power BI. Drag and drop the Period Calculation field onto the chart and switch it to a slicer element. You get two options - monthly and YTD. Switch to Horizontal orientation under General option in the Formatting tab.

You now have a slicer with two options (YTD and Month). You click between the two although the options do not do anything yet.

Create a new measure and name it Selected calculation. You will use the MIN function, which simply returns the smallest value in a column. Enter the following formula: SelectedCalc = MIN('Period Calculation'[CalcID])

All you have to do now is to link this back to your model. You need to take your AC measure and use the following DAX formula:

AC = SWITCH([SelectedCalc];
1; [AC filtered];
2; CALCULATE([AC filtered]; DATESYTD('Calendar'[Date])))

Just to explain briefly, what these functions do. SWITCH returns different results depending on the value of an expression, in this case AC filtered element in your project. If the value is 1, the expression returns the AC filtered value. If the value is 2 it calculates revenue to return the YTD value for which the DATESYTD function is used.

Make sure you download the free trial!

Try Zebra BI Visuals for Power BI

In addition to out-of-the-box support for IBCS standards, Zebra BI visuals for Power BI feature 1-click data sorting, powerful outlier handling, advanced small multiples, responsive visuals, improved navigation, and full customization. With support for Power BI, best practice reporting is now available on the desktop and mobile and in the cloud.


USAFacts Relies on Zebra BI Visuals to Open US Government Financials to Public

April 17, USAFacts released a 10-k report on US government financial using Zebra BI Visuals for Power BI. The shareable reports will drive interactive storytelling and deeper understanding of complex data.

USAFacts is a fascinating project funded by Steve Ballmer, former CEO of Microsoft. The project's aim is to make vast amounts of US government data more open, accessible, transparent and easier to use. Engineers and researchers collected and organized 30 years’ worth of data from US Treasury Department, the Office of Management and Budget, the US Census Bureau, and the Federal Reserve. They then published it on a well-organized online hub that is neutral and focused on the thing that matters most – impartial data.

On US Tax Day, the initiative launched the 10-K report for the US government – in the US, 10-K is an annual report that gives a comprehensive summary of a company's financial performance. USAFacts did that for government data.

To make their findings better accessible to the public, they turned to Zebra BI visuals on Microsoft’s Power BI platform to create some of their interactive visualizations:

You can also click "Chart view" below to see all of the visualizations interactively:

Zebra BI visuals for Power BI are a perfect fit for a project like this. Not only does it include a host of crystal clear visualizations and features, (chart slider, small multiples and native support for IBCS), its design is completely responsive, so it can be accessed on mobile devices or desktops. It can also be embedded on other websites to drive engagement. All of this makes Zebra BI visuals for Power BI the best choice for data-driven storytelling that uses clear, easy-to-understand and attractive visuals for communicating insights.

You can also find out more in Microsoft’s Power BI team announcement.

We are proud that the USAFacts team, in partnership with the Microsoft Power BI data journalism program management, has chosen our Zebra BI visuals for Power BI to bring the US government financials closer to the public. In many ways, this is for us an essential confirmation that we have have done a good job with our latest product and that our solution is a great choice for presenting business and financial data in a clear and understandable way.

We are an avid supporter of open data. Data transparency and clarity of business communication are at the very core of Zebra BI’s beliefs. It’s what we stand and work for.

USAFacts is a noble initiative and we are looking forward to supporting more projects like this!

Andrej Lapajne,
CEO at Zebra BI