2
votes

When choose a single Year on slicer I want area chart display all data from that chosen year and till the end (all years I have in my datasource). But instead it just displays me the data for single year choosing on a slicer. So I have this:

enter image description here

But I want it look like this: whatever Year I choose in slicer - chart will show all data starting from 2014 and goes till 2017.

enter image description here

I am simply following a PowerBI template example and it seems like it's possible to do that:

https://app.powerbi.com/view?r=eyJrIjoiMjc2NzExODItMjNhYy00ZWMxLWI2NGItYjFiNWMzYzUzMzhlIiwidCI6IjU3NGMzZTU2LTQ5MjQtNDAwNC1hZDFhLWQ4NDI3ZTdkYjI0MSIsImMiOjZ9

2

2 Answers

2
votes

This is doable but it requires some tricks and extra measures.

TL;DR: The slicer you see is actually served as a value picker, not as a filter. An extra measure based on the value is created and used as visual level filter for the visual to do the trick.


If you want to follow along, you can download the .pbix file from this Microsoft edX course about Power BI.

First, create a new table based on the existing Date table, with only distinct years:

Year = DISTINCT('Date'[Year])

year


Then, create a slicer with the Year column from the newly created Year table (NOT the Date table).

slicer


A measure (used as flag) is created as follows:

Flag = 
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) >= YearSelected, 1, 0)

So basically it gets the year selected from the year slicer and compare it with the year value in the date table to see if it's greater than or equal to it.


The chart is created with Year column from the Date table (NOT the Year table), and other needed measures. Flag is added to the Visual level filters and set to 1.

chart

So the Flag value will change according to the value picked in the Year slicer, and served as the actual filter to the chart displayed.


Results:

results


EDIT: on more use cases

@Oleg Try to think of how you can apply the Flag concept further. For example, if you want another chart displaying data of the same year as the slicer, you can set up another flag called SameYearFlag and only change the part of value comparison to =. Add it to the chart Visual level filter and it'll show only data in the same year. Yes, by extension, that means you can have another flags like LastYearFlag, NextYearFlag, etc, as long as it makes sense to you. The use case is up to you.

LastYearFlag = 
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(YearSelected - VALUES('Date'[Year]) = 1, 1, 0)

NextYearFlag = 
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) - YearSelected = 1, 1, 0)

SameYearFlag = 
VAR YearSelected = FIRSTNONBLANK(VALUES('Year'[Year]), 0)
RETURN
IF(VALUES('Date'[Year]) = YearSelected, 1, 0)

Examples:

multiple charts

By having only one year slicer, I can have charts with data in the same year, last year, next year and all years following, by applying different flags to them.

As said, it's up to you to come up with more interesting use cases!

1
votes

I would propose to consider the new numeric range slicer. You can just set it as "Greater than or equal to". Users can select then the initial year in the range by entering the number or dragging the slicer.

You would need to enable this feature in Power Bi Desktop, Options under "Preview features".

Is well presented in the documentation https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-slicer-numeric-range/

This is how it could look like:

enter image description here