双粒度矩阵值处理:如何将子粒度行中非所属层级的聚合值设为空值
Fixing Hierarchical Matrix Values in Power BI (Hide Aggregates on Sub-Level Rows)
Hey there! I’ve dealt with this exact issue when building hierarchical matrices in Power BI—those inherited aggregate values on sub-department rows can be really misleading. Here’s how you can fix it using DAX measures:
The Core Idea
We need to check which level of the hierarchy we’re currently viewing (department vs. sub-department) and conditionally return the value or blank accordingly.
Step-by-Step DAX Solution
Assuming you already have existing measures for Target and Actual, create adjusted versions of these measures using the ISINSCOPE function:
Adjusted Target Measure
Target Adjusted = IF( ISINSCOPE('YourTable'[SubDepartment]), // Check if we're on a sub-department row BLANK(), // Return empty for sub-departments [Original Target Measure] // Keep the aggregate value for department level )
Adjusted Actual Measure
Actual Adjusted = IF( ISINSCOPE('YourTable'[SubDepartment]), BLANK(), [Original Actual Measure] )
How It Works
ISINSCOPE('YourTable'[SubDepartment])returnsTRUEwhen the current row in the matrix is a sub-department level entry (since that column is in scope for that row).- When it’s
TRUE, we returnBLANK()which will show as empty in the matrix. - For the department level row,
ISINSCOPEreturnsFALSE, so we fall back to your original aggregate measure.
Example Results
BEFORE (Original Matrix)
| Target | Actual | Volume | |
|---|---|---|---|
| Department (二楼) | 1200 | 1300 | 13 |
| Subdepartment 1 | 1200 | 1300 | 5 |
| Subdepartment 2 | 1200 | 1300 | 4 |
| Subdepartment 3 | 1200 | 1300 | 3 |
| Subdepartment 4 | 1200 | 1300 | 1 |
AFTER (With Adjusted Measures)
| Target | Actual | Volume | |
|---|---|---|---|
| Department (二楼) | 1200 | 1300 | 13 |
| Subdepartment 1 | 5 | ||
| Subdepartment 2 | 4 | ||
| Subdepartment 3 | 3 | ||
| Subdepartment 4 | 1 |
Notes
- If your hierarchy is defined in a separate dimension table with a formal hierarchy (not just two separate columns), you can also use
PATHITEMorHIERARCHYLEVELto check the current level, butISINSCOPEis simpler for this two-level scenario. - Make sure to replace
'YourTable'and[Original Target Measure]/[Original Actual Measure]with your actual table and measure names.
内容的提问来源于stack exchange,提问作者Will Returns
相关产品推荐
相关产品推荐

