Forum Discussion

MAruna's avatar
MAruna
Icon for Helper I rankHelper I
8 months ago
Solved

Need help on Slicer interaction

Hi Team, Good Day!

I have one requirement, please help me on this.

i need one slicer like current year and previous year.

Note: when i select current year current year amount needs to display , when i select previous year previous year + current year .

when i select financial year( like this 2022-23) slicer based on the slicer selection i need to display the amount in visual.

Note: i have extracted current year is 2022, previous year 2023

How acheive this .


PFB attached Snapchart for your reference.

Like this.
Thanks in advance



  • Hi MAruna 

     

    Are you looking for an output similar to this ? 

     

    If this is what you are looking for , please create a Year option table and include the three dax measure in the pbix file I have attached 

     

     

7 Replies

  • Hi MAruna,

    You can do this in Power BI by creating one slicer table and one measure that shows the amount based on what you select.

    Step 1: Create a slicer table

    Create a new table:
    YearSelector =
    DATATABLE(
    "Selection", STRING,
    {
    { "Current Year" },
    { "Previous Year" },
    { "Financial Year" }
    }
    )

     

    Use YearSelector[Selection] in the slicer.

    Step 2: Create the final measure

    This measure checks what you selected in the slicer and shows the correct amount:

    Amount Output =
    VAR Sel = SELECTEDVALUE(YearSelector[Selection])
    VAR CY = CALCULATE([Amount], 'Date'[Year] = 2023) -- your current year
    VAR PY = CALCULATE([Amount], 'Date'[Year] = 2022) -- your previous year

    RETURN
    SWITCH(
    Sel,
    "Current Year", CY,
    "Previous Year", CY + PY,
    "Financial Year", CY + PY
    )

    • If you choose Current Year, it shows only current year amount.

    • If you choose Previous Year, it shows previous year + current year.

    • If you choose Financial Year, it shows both years together (2022–23).



     





  • MAruna,
    Can you share non-sensitive sample data with 10 rows or so and let us know the expected output according to that table? It would be helpful to answer your query.

  • Hi MAruna ,

    if I understand you right you want to change the visible columns depending on your slicer setting. Assuming that you have measures for "current year amount" and "last year amount" and your "Year option" slicer is already based on a field parameter, the following setup could be a solution:

    (your table and columns names will be slightly different)

    1) Add an extra row to your field parameter table :
    Your current field parameter table should look similar to the following one:

    Parameter = {
        ("Customer Sales", NAMEOF('_Measures'[Customer Sales]), 0),
        ("Customer Sales (Last Year)", NAMEOF('_Measures'[Customer Sales (Last Year)]), 1)
    }
    • Go to table or report view
    • Select you field parameter table
    • Copy first line and duplicate it as last line
    • Give the last line another name (first column) and the order 2 and don't forget to add a colon at the end of the second line
    • The result should look similar to the following expression
    Parameter = {
        ("Customer Sales", NAMEOF('_Measures'[Customer Sales]), 0),
        ("Customer Sales (Last Year)", NAMEOF('_Measures'[Customer Sales (Last Year)]), 1),
        ("Customer Sales 2", NAMEOF('_Measures'[Customer Sales]), 2)
    }
     
    2) Add an extra column to your field parameter table:
    My Selection = SWITCH(Parameter[Parameter Order],
        0, "Current",
        1, "Previous",
        2, "Previous"
    )
    3) Your field parameter table should look like:

     

    4) Create a new "My selection" table:

    5) Define a relationship between the MySelection Columns of the two tables

    6) Assign the Title column of the My selection table to a slicer

    7) Create a table visual

    8 ) Assign your finacial periods and the field parameter to the table

     

    That's the result:

     

    Is it that what you want?

     
     

     

  • Hi,

    I do not understand your objective.  If you have a FY slicer, then what is the purpose of a CY/PY slicer?

    • MAruna's avatar
      MAruna
      Icon for Helper I rankHelper I

      Ashish_Mathur , Hi Ashish.

      If we select select financial year (Ex : 2023-23 ) in the table needs to dispaly amount.

      If we select CY or PY based on the financial year Current year and previous year amount  value needs to dispaly in the table

  • Abhilash_P , Hi Abilash

    Thanks for your efforts.

    But it is not inetrating with the visual.

    Same measure only i am using.

    Amount Output =
    VAR Sel = SELECTEDVALUE(YearSelector[Selection])
    VAR CY = CALCULATE(SUM('Global-Superstore'[Sales]), 'Date'[Year] = YEAR(MAX('Date'[CurrFY]))) -- your current year
    VAR PY = CALCULATE(SUM('Global-Superstore'[Sales]), 'Date'[Year] = YEAR(MAX('Date'[CurrFY]))-1) -- your previous year

    RETURN
    SWITCH(
    Sel,
    "Current Year", CY,
    "Previous Year", CY + PY,
    "Financial Year", CY + PY
    )
  • Hi MAruna 

     

    Are you looking for an output similar to this ? 

     

    If this is what you are looking for , please create a Year option table and include the three dax measure in the pbix file I have attached