Forum Discussion
Change Measures used based on Slicer Selection
Hello - I am trying to set up a dashboard that allows me to select year (2024 or 2025) and based on that the measures in the dashboard change.
I have a static table with a year field containing 2024 and 2025. I also have separate measures with "2024 Savings" and "2025 Savings". If I select 2024 I want the dashboard to populate 2024 savings and if 2025 then show 2025 savings.
I cannot figure out the measure / column to create the IF "Year Selection'=2024 then "2024 Savings" ELSEIF "Year Selection"=2025 then "2025 Savings", else NULL.
The data is not set up to just put in a year filter and everything will update. The separate "2024 Savings" and "2025 Savings" columns are needed.
Appreciate any help in advance!
- Anonymous1 year ago
Hi bburzanko3 ,
I'm not sure how your dataset is designed, here is my sample.The data table is as follows.
Create the following measure for dynamic switching of savings.
SelectedYearSavings = VAR SelectedYear = CALCULATE ( SELECTEDVALUE ( 'Table'[Year] ), ALLSELECTED () ) RETURN SWITCH ( SelectedYear, 2024, [2024 Savings], 2025, [2025 Savings] )
The final resutl is as follows. Hopefully it will meet your needs.
Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 Replies
- vicky_
Super User
Is savings the only measure that you want to toggle between ? If so, consider using a Field Parameter with your 2024 and 2025 Savings measures - https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters With this approach, you won't need your static year table.
The only thing that you might need to tweak is the no-selection. You can manually edit the code to have an option to return a BLANK() measure if the year is not selected.
- bburzanko3Regular Visitor
No Savings wont be the only measure that changes. For example there will also be a "Target" field which would be based off of "2024 Target" and "2025 Target"
The goal would be when i toggle between the different "Year Selections" the measures would change appropriately.
I was thinking for each measure i would have a formula on back saying if 2024 then "2024 measure", if 2025 "2025 measure" and so on.
- AnonymousNot applicable
Hi bburzanko3 ,
I'm not sure how your dataset is designed, here is my sample.The data table is as follows.
Create the following measure for dynamic switching of savings.
SelectedYearSavings = VAR SelectedYear = CALCULATE ( SELECTEDVALUE ( 'Table'[Year] ), ALLSELECTED () ) RETURN SWITCH ( SelectedYear, 2024, [2024 Savings], 2025, [2025 Savings] )
The final resutl is as follows. Hopefully it will meet your needs.
Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.