Forum Discussion
How to create Boolean Flag based on selected slicer value ?
- 1 year ago
cruncher , Try using below steps
Create a new table in Power BI for the parameter selection. This table will have two values: "Current Quarter" and "Previous Quarter".
Add a slicer to your report using the ParameterTable to allow users to select between "Current Quarter" and "Previous Quarter".
Create a measure that calculates the sales based on the selected parameter. This measure will check the selected value and sum the sales accordingly.
SelectedSales =
VAR SelectedParameter = SELECTEDVALUE(ParameterTable[Parameter])
RETURN
SWITCH(
SelectedParameter,
"Current Quarter", CALCULATE(SUM('YourTable'[Sales]), 'YourTable'[Current Quarter Flag] = 1),
"Previous Quarter", CALCULATE(SUM('YourTable'[Sales]), 'YourTable'[Previous Quarter Flag] = 1),Create a Card Visual:
Add a card visual to your report and set the value to the SelectedSales measure. This will display the total sales based on the selected quarter from the slicer. - Anonymous1 year ago
Hi cruncher ,
About:Which approach (SUMX vs Calculate) is more optimized as per your experience if we have 25 Million rows in a table.For 25 million rows the performance is almost the same.
And here is my sample data:Here is the parameter table:
You can use this DAX to create a measure:
IsSelectedSource = VAR SelectedParam = SELECTEDVALUE(ParameterTable[Source]) RETURN IF ( ISFILTERED(ParameterTable[Source]), IF( MAX('Table'[Source]) = SelectedParam, TRUE(), FALSE() ), TRUE() )And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
cruncher , Try using below steps
Create a new table in Power BI for the parameter selection. This table will have two values: "Current Quarter" and "Previous Quarter".
Add a slicer to your report using the ParameterTable to allow users to select between "Current Quarter" and "Previous Quarter".
Create a measure that calculates the sales based on the selected parameter. This measure will check the selected value and sum the sales accordingly.
SelectedSales =
VAR SelectedParameter = SELECTEDVALUE(ParameterTable[Parameter])
RETURN
SWITCH(
SelectedParameter,
"Current Quarter", CALCULATE(SUM('YourTable'[Sales]), 'YourTable'[Current Quarter Flag] = 1),
"Previous Quarter", CALCULATE(SUM('YourTable'[Sales]), 'YourTable'[Previous Quarter Flag] = 1),
Create a Card Visual:
Add a card visual to your report and set the value to the SelectedSales measure. This will display the total sales based on the selected quarter from the slicer.
Thanks bhanu_gautam for the alternate solution. After a short struggle, I was able to achieve this using below calc
SelectedSales =
VAR SelectedParameter = SELECTEDVALUE(ParameterTable[Parameter])
RETURN
SWITCH(
SelectedParameter,
"Current Quarter",SUMX('YourTable','YourTable'[Sales]*'YourTable'[Current Quarter Flag]),
"Previous Quarter",SUMX('YourTable','YourTable'[Sales]*'YourTable'[Previous Quarter Flag])
)
Which approach (SUMX vs Calculate) is more optimized as per your experience if we have 25 Million rows in a table.
- cruncher1 year agoHelper II
In this similar context, I am facing another problem. We have a source column in table that contains different values like Sales,Discount,Forecast.
I have a created an source parameter using parameter table similar approach.
How can i create an Boolean flag based on Selected value in parameter so that when Sales in selected, It will filter True for all rows from table where Source=Sales and False for where source <> Sales.
This Boolean flag should be dynamic so that visuals are filtered dynamically as per slicer selection. Should I have to create an calculated column or Measure for same ? How to decide when to create calculated column vs Measure ?
I am thinking to put that Boolean flag in filters so that all measures related to sales are filtered in one go
- Anonymous1 year agoNot applicable
Hi cruncher ,
About:Which approach (SUMX vs Calculate) is more optimized as per your experience if we have 25 Million rows in a table.For 25 million rows the performance is almost the same.
And here is my sample data:Here is the parameter table:
You can use this DAX to create a measure:
IsSelectedSource = VAR SelectedParam = SELECTEDVALUE(ParameterTable[Source]) RETURN IF ( ISFILTERED(ParameterTable[Source]), IF( MAX('Table'[Source]) = SelectedParam, TRUE(), FALSE() ), TRUE() )And the final output is as below:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- cruncher1 year agoHelper II
Thank you Anonymous . It works as expected