Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago
Solved

Current year by default as no year selected

Hello

I have a report that has a segmentation of data by year, where I visualize my amounts depending on the selected year. I need that when I DO NOT select any year the graphs or measures show me by default the amounts of the maximum (or current) year. There is a way to do it.

Thank you

  • In Power BI using DAX, you can create a measure that checks if the slicer value is blank and, if so, applies the maximum year as the filter. Here’s how you can do it:

    1. Create a Year Slicer: Ensure you have a slicer in your Power BI report that allows users to select a year.

    2. Create a Measure: Write a DAX measure to apply the maximum year when the slicer is blank.

    Here is an example of how you can do this:

     

    SelectedYear =
    IF(
        ISBLANK(SELECTEDVALUE('Calendar'[Year])),
        MAX('Calendar'[Year]),
        SELECTEDVALUE('Calendar'[Year])
    )

     

    • 'Calendar'[Year] is the column from your date table (replace Calendar with your actual date table name).
    • SELECTEDVALUE('Calendar'[Year]) gets the value selected in the slicer.
    • ISBLANK(SELECTEDVALUE('Calendar'[Year])) checks if the slicer value is blank.
    • MAX('Calendar'[Year]) gets the maximum year from your date table.
    1. Use the Measure in Your Visuals: Apply this measure as a filter or use it directly in your visuals. For instance, if you have a visual that needs to be filtered by year, you can use the SelectedYear measure to ensure it always uses the maximum year when no year is selected in the slicer.

    To apply this measure as a filter, you can use it in the Filter pane by setting it in the filter section of your visuals.

    Here is an example of how you might use it in a visual calculation:

     

    SalesAmountFiltered =
    CALCULATE(
        SUM(Sales[SalesAmount]),
        'Calendar'[Year] = [SelectedYear]
    )

     

     

1 Reply

  • aduguid's avatar
    aduguid
    Icon for Memorable Member rankMemorable Member

    In Power BI using DAX, you can create a measure that checks if the slicer value is blank and, if so, applies the maximum year as the filter. Here’s how you can do it:

    1. Create a Year Slicer: Ensure you have a slicer in your Power BI report that allows users to select a year.

    2. Create a Measure: Write a DAX measure to apply the maximum year when the slicer is blank.

    Here is an example of how you can do this:

     

    SelectedYear =
    IF(
        ISBLANK(SELECTEDVALUE('Calendar'[Year])),
        MAX('Calendar'[Year]),
        SELECTEDVALUE('Calendar'[Year])
    )

     

    • 'Calendar'[Year] is the column from your date table (replace Calendar with your actual date table name).
    • SELECTEDVALUE('Calendar'[Year]) gets the value selected in the slicer.
    • ISBLANK(SELECTEDVALUE('Calendar'[Year])) checks if the slicer value is blank.
    • MAX('Calendar'[Year]) gets the maximum year from your date table.
    1. Use the Measure in Your Visuals: Apply this measure as a filter or use it directly in your visuals. For instance, if you have a visual that needs to be filtered by year, you can use the SelectedYear measure to ensure it always uses the maximum year when no year is selected in the slicer.

    To apply this measure as a filter, you can use it in the Filter pane by setting it in the filter section of your visuals.

    Here is an example of how you might use it in a visual calculation:

     

    SalesAmountFiltered =
    CALCULATE(
        SUM(Sales[SalesAmount]),
        'Calendar'[Year] = [SelectedYear]
    )