Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
cheezter88
Frequent Visitor

Clustered Bar Chart filtered to Selected Year & Prev Year

Been racking my brain on this and have scoured this site and many others for an answer.

My data is in the following format:

firstUserDefaultChannelGroupsessionsyear
Paid Search10002024
Paid Search9002023
Referral1002024
Referral902023
Organic Social15002025
Organic Social10002024
Organic Social7502023
Paid Other2002024
etc.etc.etc.

I have Clustered Bar Chart built in the following way:

cheezter88_0-1738862773359.pngcheezter88_1-1738862891316.png

 

I have a slicer on the page for [year] that filters other visuals to show just the selected year, only 1 year may be selected at a time.
I need the Clustered Bar Chart above to only show the selected year and the previous year (i.e. 2024 is selected in slicer so the Bar Chart shows data for 2024 & 2023), other than that the above Bar Chart is exactly what I need.

 

I have tried the follwoing measure to create a new source for [sessions]:

Measure =
    var filteredYear = SELECTEDVALUE('PROP - GA4 SourceMedium'[year])
return
    CALCULATE(SUM('PROP - GA4 SourceMedium'[sessions])
        ,REMOVEFILTERS('PROP - GA4 SourceMedium')
        ,'PROP - GA4 SourceMedium'[year] = filteredYear
            || 'PROP - GA4 SourceMedium'[year] = filteredYear - 1
    )
This provides weird total numbers for all [firstUserDefaultChannelGroup] and only shows the filtered [year] instead of 2 years.
 
I have also tried the following measure to use the visual level filter but have not had any luck with those either. I am unsure if [year] being within the Legend part of the visual has caused any additional issues. 
Any help is greatly appreciated!
1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @cheezter88 
To get the wanted result you need a disconnected years table  ( for the slicer):

Ritaf1983_0-1739085241709.png

Ritaf1983_1-1739085286465.png

Then you can create a flag measure like :

flag =
var selectedY =
SELECTEDVALUE(Years[year])
var PreviousY = selectedY-1
Return
if(SELECTEDVALUE('Table'[year])= PreviousY || SELECTEDVALUE('Table'[year])= selectedY,1,0)
This measure will be a filter for the graph :
Ritaf1983_2-1739085372615.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

1 REPLY 1
Ritaf1983
Super User
Super User

Hi @cheezter88 
To get the wanted result you need a disconnected years table  ( for the slicer):

Ritaf1983_0-1739085241709.png

Ritaf1983_1-1739085286465.png

Then you can create a flag measure like :

flag =
var selectedY =
SELECTEDVALUE(Years[year])
var PreviousY = selectedY-1
Return
if(SELECTEDVALUE('Table'[year])= PreviousY || SELECTEDVALUE('Table'[year])= selectedY,1,0)
This measure will be a filter for the graph :
Ritaf1983_2-1739085372615.png

The pbix is attached

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors