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
alya1
Helper V
Helper V

Is there a way to filter visual based on parameter (x-axis) selected?

Hi all,


I was able to use the parameter fields trick to create a filter between calendar year and fiscal year on the x-axis of a bar chart. (https://www.youtube.com/watch?v=ppvC3cf-ZLQ)

But I don't want to show any incomplete yearly data.

For example, if it's in FY, I don't want to show FY 2019 (April 2019-March 2020) since my data starts from January 2020. But if I unselect FY year 2019 on filters on this visual pane, then when I switch to CY, the filter carries over so it continous to hide April 2019-March 2020 and now my CY 2020 data is incomplete :,) 

 

Does anyone know of another way to filter visuals based on parameter selected? 
Thank you!

2 REPLIES 2
hackcrr
Super User
Super User

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

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? 

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 Kudoed Authors