sql server - How to display data in area chart starting from the year chosen on a slicer and get all following years in Power BI -


when choose single year on slicer want area chart display data chosen year , till end (all years have in datasource). instead displays me data single year choosing on slicer. have this:

enter image description here

but want this: whatever year choose in slicer - chart show data starting 2014 , goes till 2017.

enter image description here

i following powerbi template example , seems it's possible that:

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

this doable requires tricks , measures.

tl;dr: slicer see served value picker, not filter. extra measure based on value created , used visual level filter visual trick.


if want follow along, can download .pbix file microsoft edx course power bi.

first, create new table based on existing date table, distinct years:

year = distinct('date'[year]) 

year


then, create slicer year column newly created year table (not date table).

slicer


a measure (used flag) created follows:

flag =  var yearselected = firstnonblank(values('year'[year]), 0) return if(values('date'[year]) >= yearselected, 1, 0) 

so gets year selected year slicer , compare year value in date table see if it's greater or equal it.


the chart created year column date table (not year table), , other needed measures. flag added visual level filters , set 1.

chart

so flag value change according value picked in year slicer, , served actual filter chart displayed.


results:

results


edit: on more use cases

@oleg try think of how can apply flag concept further. example, if want chart displaying data of same year slicer, can set flag called sameyearflag , change part of value comparison =. add chart visual level filter , it'll show data in same year. yes, extension, means can have flags lastyearflag, nextyearflag, etc, long makes sense you. use case 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 1 year slicer, can have charts data in same year, last year, next year , years following, applying different flags them.

as said, it's come more interesting use cases!


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -