Forum Discussion

rmcgrath's avatar
rmcgrath
Advocate II
1 year ago
Solved

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)

 

 

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:

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

 

 

  • Anonymous's avatar
    Anonymous
    1 year ago

    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.

1 Reply

  • Anonymous's avatar
    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.