Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Power BI switch Data in visuals through button

Hello there,

 

the question is really simple, yet for me as a beginner quite the opposite from simple.

 

I am currently studying Business Analyst Specialist and we have a task to switch visuals based on a button. But we are not supposed to use bookmarks but DAX to switch between the requested data.

 

For example, we need to add three buttons: Gross, Net, Profit

 

Each Button is supposed to switch between those values. I added a new table with all 3 names, but have no idea how to continue. I have set up a measure for each of the three options but I have no idea how to connect these through DAX.

 

anybody here that could help?

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    tharunkumarRTK Thanks for your reply!
    Here is my sample data:

    I create three measures:

    Then use Field-parameter:

    And put the parameter into the table visual:

    The final output is as below:

    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept both of the answers as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hello, thank you for your answers. So, both of your options work. But I did it this way:

     

    Choices = IF ( SELECTEDVALUE(Choice[Button]) = "Gross", [Gross], IF(SELECTEDVALUE(Choice[Button]) = "Net", [Net], IF(SELECTEDVALUE(Choice[Button]) = "Profit", [Profit])))
     
    This worked fine for me.
     
    Now, I have another question.
     
    I need to calculate values based on the year that is highlighted through a slicer. I need a formula that calculates the values of the last year based o nthe year that is selected. I did that through this:
     
    Last_year_values =
    VAR SelectedMetrik = SELECTEDVALUE(Choice[Button])
    VAR CurrentYear = YEAR(MAX(Dates[Date]))
    VAR LastYear = CurrentYear - 1
    RETURN
    CALCULATE (
    SWITCH (
    SelectedMetrik,
    "Gross", [Gross],
    "Net", [Net],
    "Profit", [Profit]
    ),
    FILTER ( ALL(Dates), YEAR(Dates[Date]) = LastYear )
    )
     
    That workes just fine. However, if I select a specific month of the current year, it is supposed to calculate last years values only for that selected month. But I fail in achieving this. Could you help me with that too? 🙂

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    tharunkumarRTK Thanks for your reply!
    Here is my sample data:

    I create three measures:

    Then use Field-parameter:

    And put the parameter into the table visual:

    The final output is as below:

    Best Regards,
    Dino Tao
    If this post helps, then please consider Accept both of the answers as the solution to help the other members find it more quickly.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello, thank you for your answers. So, both of your options work. But I did it this way:

     

    Choices = IF ( SELECTEDVALUE(Choice[Button]) = "Gross", [Gross], IF(SELECTEDVALUE(Choice[Button]) = "Net", [Net], IF(SELECTEDVALUE(Choice[Button]) = "Profit", [Profit])))
     
    This worked fine for me.
     
    Now, I have another question.
     
    I need to calculate values based on the year that is highlighted through a slicer. I need a formula that calculates the values of the last year based o nthe year that is selected. I did that through this:
     
    Last_year_values =
    VAR SelectedMetrik = SELECTEDVALUE(Choice[Button])
    VAR CurrentYear = YEAR(MAX(Dates[Date]))
    VAR LastYear = CurrentYear - 1
    RETURN
    CALCULATE (
    SWITCH (
    SelectedMetrik,
    "Gross", [Gross],
    "Net", [Net],
    "Profit", [Profit]
    ),
    FILTER ( ALL(Dates), YEAR(Dates[Date]) = LastYear )
    )
     
    That workes just fine. However, if I select a specific month of the current year, it is supposed to calculate last years values only for that selected month. But I fail in achieving this. Could you help me with that too? 🙂