Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
I'm looking to build a DAX statement based on the visual tables, and I've attached a sample image for reference. I have a toggle button that shows and hides certain tables, but I need a total that only includes the visible tables. Currently, I'm getting the sum from all tables, not just the ones that are unhidden. Could you help me with this? Thank you
Solved! Go to Solution.
Hi @msam1977_SM
In Power BI, DAX measures cannot detect the visibility state of visuals controlled by bookmarks or selection panes. However, you can achieve your goal by linking the table visibility to data selections that DAX can reference. Here's how:
Solution:
TableVisibility =
DATATABLE(
"TableName", STRING,
{
{"Table1"},
{"Table2"},
{"Table3"} // Add as many tables as needed
}
)
Total_Table1 = SUM('Table1'[Value])
Total_Table2 = SUM('Table2'[Value])
TotalVisible =
VAR SelectedTables = VALUES(TableVisibility[TableName])
RETURN
SUMX(
SelectedTables,
SWITCH(
TRUE(),
TableVisibility[TableName] = "Table1", [Total_Table1],
TableVisibility[TableName] = "Table2", [Total_Table2],
TableVisibility[TableName] = "Table3", [Total_Table3],
0
)
)
Important Notes:
Conclusion:
By linking table visibility to slicer selections that your DAX measures can reference, you can dynamically calculate totals based on which tables are visible to the user. This approach aligns the data model with the report visuals, providing the functionality you need.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Hi @msam1977_SM ,
DAX
Visible Total =
CALCULATE(
SUM(Sales[Amount]),
FILTER(
'Visibility Control',
'Visibility Control'[IsVisible] = 1
)
)
If you provide more details about how you're toggling the tables (using bookmarks, buttons, or slicers), I can give more specific advice or DAX formulas tailored to your setup.
Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂
Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Hi @msam1977_SM ,
You can use measure to manually calculate the desired result separately and then use bookmark to switch between different visualizations. You can refer to the following example, details can be found in the attachment.
Measure =
VAR _sum1 = CALCULATE(SUM(financials[ Sales]),FILTER(ALL(financials),'financials'[Year] = 2013 || 'financials'[Year] = 2014))
VAR _sum2 = CALCULATE(SUM(financials[ Sales]),FILTER(ALL(financials),'financials'[Month Number] = 1 || 'financials'[Month Number] = 2 || 'financials'[Month Number] = 3))
RETURN
_sum1 + _sum2
Measure 2 =
VAR _sum1 = CALCULATE(SUM(financials[ Sales]),FILTER(ALL(financials),'financials'[Year] = 2013 || 'financials'[Year] = 2014))
VAR _sum2 = CALCULATE(SUM(financials[ Sales]),FILTER(ALL(financials),'financials'[Month Number] = 1 || 'financials'[Month Number] = 2 || 'financials'[Month Number] = 3))
VAR _sum3 = CALCULATE(SUM(financials[ Sales]),FILTER(ALL(financials), 'financials'[Date].[QuarterNo] = 1 || 'financials'[Date].[QuarterNo] = 2))
RETURN
_sum1 + _sum2 + _sum3
If your Current Period does not refer to this, please clarify in a follow-up reply.
Best Regards,
Clara Gong
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you so much for the help!! I was able to resolve the issues. I have posted the solution too.
Hi @msam1977_SM
In Power BI, DAX measures cannot detect the visibility state of visuals controlled by bookmarks or selection panes. However, you can achieve your goal by linking the table visibility to data selections that DAX can reference. Here's how:
Solution:
TableVisibility =
DATATABLE(
"TableName", STRING,
{
{"Table1"},
{"Table2"},
{"Table3"} // Add as many tables as needed
}
)
Total_Table1 = SUM('Table1'[Value])
Total_Table2 = SUM('Table2'[Value])
TotalVisible =
VAR SelectedTables = VALUES(TableVisibility[TableName])
RETURN
SUMX(
SelectedTables,
SWITCH(
TRUE(),
TableVisibility[TableName] = "Table1", [Total_Table1],
TableVisibility[TableName] = "Table2", [Total_Table2],
TableVisibility[TableName] = "Table3", [Total_Table3],
0
)
)
Important Notes:
Conclusion:
By linking table visibility to slicer selections that your DAX measures can reference, you can dynamically calculate totals based on which tables are visible to the user. This approach aligns the data model with the report visuals, providing the functionality you need.
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Thank you for the idea! I made some customizations to my Power BI setup. I created three tables, each dedicated to a specific slicer, and connected them to the data to enable filtering. This approach allowed me to remove the bookmark or toggle functionality from the code.
For the "TotalYearly" calculation, I used the following code as a reference, which might be helpful to others:
_TotalValue =
VAR _SumProd_Month =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Month",
'Calendar Year Rebates'[StageFlag] = "PROD"
)
VAR _SumStage_Month =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Month",
'Calendar Year Rebates'[StageFlag] = "Stage"
)
VAR _SM_Month = SELECTEDVALUE(Dim_Month[ToggleMonth])
VAR _MonthValue = IF(
HASONEVALUE(Dim_Month[ToggleMonth]),
IF(_SM_Month = "ON", _SumStage_Month, _SumProd_Month),
0
)
VAR _SumProd_Quarter =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Quarter",
'Calendar Year Rebates'[StageFlag] = "PROD"
)
VAR _SumStage_Quarter =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Quarter",
'Calendar Year Rebates'[StageFlag] = "Stage"
)
VAR _SM_Quarter = SELECTEDVALUE(Dim_Qtr[ToggleQtr])
VAR _QuarterValue = IF(
HASONEVALUE(Dim_Qtr[ToggleQtr]),
IF(_SM_Quarter = "ON", _SumStage_Quarter, _SumProd_Quarter),
0
)
VAR _SumProd_Year =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Year",
'Calendar Year Rebates'[StageFlag] = "PROD"
)
VAR _SumStage_Year =
CALCULATE(
SUM('Calendar Year Rebates'[Rebate]),
'Calendar Year Rebates'[Type] = "Year",
'Calendar Year Rebates'[StageFlag] = "Stage"
)
VAR _SM_Year = SELECTEDVALUE(Dim_Year[ToggleYear])
VAR _YearValue = IF(
HASONEVALUE(Dim_Year[ToggleYear]),
IF(_SM_Year = "ON", _SumStage_Year, _SumProd_Year),
0
)
VAR _TotalValue = _MonthValue + _QuarterValue + _YearValue
VAR __ValueToShow = IF(ISBLANK(_TotalValue), "-", _TotalValue)
RETURN
IF([Complex Selector]=1,__ValueToShow,BLANK())
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
11 | |
10 | |
10 | |
10 |
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
8 |