Forum Discussion

weeksd's avatar
weeksd
Frequent Visitor
5 years ago
Solved

Visualizations with different filters

I have a requirement to create a report in which a user will select a year from a slicer.   There needs to be 2 bar charts on the report with one showing the year selected in the slicer.  The other c...
  • MFelix's avatar
    MFelix
    5 years ago

    Hi weeksd ,

     

    The example I have used is just on some mockup data I have and based on months has I reported, so each month have is own bar chart.

     

    In Power BI you can achieve this by using a measure has I refered previously or using the samll multiples making a filter based on the information.

     

    In Power BI calculations are based on context meaning that filters, columns, others visualizations and so on influence the result of your visualizations. This also means that the way you have your data setup also impacts the calculations.

     

    If you unpivot your data you will only need a single measure for the previous year calculation, however if you keep your model with the A, B and C column you will need to have more than one measure.

     

    For using the small multiples you just need to adjust to show the last 2 years.

     

    I have pickup your data again and made a small file with both options, I also added 2019 data to have the filtering. Also only have to slicers but you can had has many has you need.

     

    Using the previous year measure you need to have the use of 3 measures:

    Previous Year A = CALCULATE(SUM(DATA[A]),FILTER(ALL(DATA[Year]), DATA[Year]= MAX(DATA[Year]) -1))
    
    Previous Year B = CALCULATE(SUM(DATA[B]),FILTER(ALL(DATA[Year]), DATA[Year]= MAX(DATA[Year]) -1))
    
    Previous Year C = CALCULATE(SUM(DATA[C]),FILTER(ALL(DATA[Year]), DATA[Year]= MAX(DATA[Year]) -1))

    Result is below:

    Using the small multiples you need to create a table or the years and a measure for the filter:

     

    TABLE Years = DISTINCT(DATA[Year])
    
    YearFilter = if(VALUES(DATA[Year]) <= MAX(Years[Year]) && VALUES(DATA[Year]) >= MAX(Years[Year]) -1 , 1)

    Now use the year from the new table has you slicer and the Yearfilter on your visualization setting up the value for non blank values:

     

    Check PBIX file attach.

     

    Believe that probably I'm not understanding your request but be aware that the interactions between your visualizations and your measures and calculations is very important in Power BI and this concept makes all the difference between the results.

     

    If  I can assist in any other way please tell me.

    PRevious_Small.pbix23 KB