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 ,
In this case, I recommend using the calendar table as a dimension table and establishing a relationship between the calendar table and the fact table. This setup allows you to take advantage of standard DAX time intelligence functions, including Quarter-to-Date and Previous Quarters. This approach is simpler, requires less maintenance, and provides greater flexibility.
Best regards,
- cruncher1 year agoHelper II
Thanks DataNinja777 for the suggestion. We have a calender table in db and these flags are coming from that table only. I want to avoid the calculation at PowerBI level which I believe will slow down the loading time of view.