Forum Discussion
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?
- Anonymous2 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. - Anonymous2 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 - 1RETURNCALCULATE (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
- tharunkumarRTKSuper User
Anonymous
Create three measures, Gross, Net and Profit and create Field parameter for switching the measure in the visual.You can refer this document for detailed explanation: https://learn.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters
If the post helps please give a thumbs up
If it solves your issue, please accept it as the solution to help the other members find it more quickly.
Tharun
- AnonymousNot 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. - AnonymousNot 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 - 1RETURNCALCULATE (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? 🙂