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.
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.
Thank you Anonymous . It works as expected