Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
cruncher
Helper II
Helper II

How to create Boolean Flag based on selected slicer value ?

Hi Experts,

 

This is the sample data of my table.

 

RegionVerticalBusiness UnitQuarterSalesCurrent Quarter FlagPrevious Quarter Flag
EastVert_1BU1Q3 24352901
EastVert_1BU2Q3 24370201
EastVert_1BU3Q3 24318201
EastVert_2BU1Q3 24493401
EastVert_3BU2Q3 24125701
WestVert_1BU1Q3 2454501
WestVert_1BU2Q3 24360201
WestVert_1BU3Q3 24223301
WestVert_2BU1Q3 24348501
WestVert_3BU2Q3 24199501
EastVert_1BU1Q4 24739210
EastVert_1BU2Q4 24853110
EastVert_1BU3Q4 24337910
EastVert_2BU1Q4 24146210
EastVert_3BU2Q4 24500410
WestVert_1BU1Q4 24287210
WestVert_1BU2Q4 2425510
WestVert_1BU3Q4 24523110
WestVert_2BU1Q4 24963210
WestVert_3BU2Q4 24778610

 

 

I want to create an card visual to show the sales based on an Drop Down parameter named Selected quarter.

 

1. If Selected value of parameter is Current Quarter then I want to sum all the sales where current quarter flag =1 or Multiple the sales with Current quarter flag which also return the same thing.

 

2. If Selected value of parameter is Previous Quarter then I want to sum all the sales where previous quarter flag =1 or Multiple the sales with Previous quarter flag which also return the same thing.

 

How to achieve this. I have an idea this can be achieved using Parameter table but not sure how to implement this.

 

Please help.

 

Thanks

2 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@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.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

Anonymous
Not 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:

vjunyantmsft_0-1730945809286.png

Here is the parameter table:

vjunyantmsft_1-1730945837714.png

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:

vjunyantmsft_2-1730945955580.png

vjunyantmsft_3-1730945961595.png

vjunyantmsft_4-1730945969265.png


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.

View solution in original post

7 REPLIES 7
DataNinja777
Super User
Super User

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,

 

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.

bhanu_gautam
Super User
Super User

@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.

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






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.

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

Anonymous
Not 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:

vjunyantmsft_0-1730945809286.png

Here is the parameter table:

vjunyantmsft_1-1730945837714.png

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:

vjunyantmsft_2-1730945955580.png

vjunyantmsft_3-1730945961595.png

vjunyantmsft_4-1730945969265.png


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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.