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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rmcgrath
Advocate II
Advocate II

X-Axis format

I have the following line chart where the X-Axis is controlled by a Parameter (Age or Weeks).  What I would like to happen is if Weeks is selected, then it displays 1 full year (depending on which year is selected from another slicer (Slicer is called "Year" and currently has the following values:  2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 and 2024)

rmcgrath_0-1729182825928.png

 

 

So, for example, if the user selects "2023" in the Year slicer, then the X-axis for Weeks would display all the weeks for 2023 only.  I currently am using the filter but I have to do that manually:

rmcgrath_1-1729182854698.png

Can I build in a DAX measure that would filter it each time to the correct year?

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rmcgrath ,

 

Try the following expression:

FilteredWeeks = 
VAR SelectedYear = SELECTEDVALUE('Year'[Year])
VAR SelectedParameter = SELECTEDVALUE('Parameter'[Parameter])
RETURN
IF(
    SelectedParameter = "Weeks",
    CALCULATE(
        SUM('YourTable'[Value]), 
        FILTER(
            'YourTable', 
            YEAR('YourTable'[Date]) = SelectedYear
        )
    ),
    SUM('YourTable'[Value])
)

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @rmcgrath ,

 

Try the following expression:

FilteredWeeks = 
VAR SelectedYear = SELECTEDVALUE('Year'[Year])
VAR SelectedParameter = SELECTEDVALUE('Parameter'[Parameter])
RETURN
IF(
    SelectedParameter = "Weeks",
    CALCULATE(
        SUM('YourTable'[Value]), 
        FILTER(
            'YourTable', 
            YEAR('YourTable'[Date]) = SelectedYear
        )
    ),
    SUM('YourTable'[Value])
)

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.