Forum Discussion
Is there a way to filter visual based on parameter (x-axis) selected?
Hi, alya1
First, create a parameter table that contains the different year types you want to switch between (Calendar Year and Fiscal Year).
YearTypeParameter =
DATATABLE(
"YearType", STRING,
{
{"Calendar Year"},
{"Fiscal Year"}
}
)Create a measure to capture the selected parameter from the parameter table.
SelectedYearType =
IF(
HASONEVALUE('YearTypeParameter'[YearType]),
VALUES('YearTypeParameter'[YearType]),
"Calendar Year"
)Create a measure that will dynamically filter the data based on the selected parameter and exclude incomplete yearly data.
CompleteYearFilter =
VAR MaxYear =
IF(
[SelectedYearType] = "Calendar Year",
YEAR(TODAY()),
IF(MONTH(TODAY()) >= 4, YEAR(TODAY()), YEAR(TODAY()) - 1)
)
RETURN
IF(
[SelectedYearType] = "Calendar Year",
YEAR('YourTable'[DateColumn]) < MaxYear,
IF(
MONTH('YourTable'[DateColumn]) >= 4,
YEAR('YourTable'[DateColumn]) < MaxYear,
YEAR('YourTable'[DateColumn]) <= MaxYear
)
)Use the CompleteYearFilter measure in your visuals to filter the data. You can do this by setting the filter condition in the visual level filters.
Add a slicer visual to your report. Use the YearTypeParameter[YearType] column in this slicer.
Go to the Visual Level Filters pane for your bar chart. Add the CompleteYearFilter measure and set it to filter to 1 (which means TRUE).
If you need more complex conditions or adjustments, you can refine the CompleteYearFilter measure. The idea is to dynamically adjust the filtering logic based on the current date and the selected parameter (Calendar Year or Fiscal Year)
hackcrr
If this post helps, then please consider Accept it as the solution and kudos to this post to help the other members find it more quickly
- alya12 years ago
Helper V
Thank you hackrr! I think this is getting close! But when I try to type in my table and column names for 'YourTable'[DateColumn] I don't think DAX can find it as it doesn't autopopular + red underline. Would you know the reason?