Trying to create Organization Chart using custom visuals in Power BI Desktop, the requirement is to show chart with filtered data which applies by Slicer on department column.
I struck with the limitation of custom visual (which logical), to get proper chart in visual, data-set must have a Root Node, In my scenario ReportsTo
column should be null
to identify as root node.
Managed to make Reportsto
column null
in each department within SQL view using ROW_NUMBER () OVER (PARTITION BY EmpDepartment Order by EmpGrade desc
and CASE
logic. But this already processed data, i'm looking for something during filter selection, so that when user select 2 departments in slicer custom visual won't crash.
I tried following DAX in Power BI desktop to get the RANK based on Grade
with filtered data, Unfortunately, the DAX work as Measure not as Calculated Column, and With the measure i'm unable to get expected result when tried a calculated column using IF([RANK]=1,BLANK(), ('Table'[ReportsTo]))
Note: Index column added in Power BI Desktop - Edit Queries page
RANK =
MINX (
FILTER (
SELECTCOLUMNS (
ALLSELECTED ('Table'),
"index", 'Table'[Index],
"rank", RANKX ( ALLSELECTED ( 'Table' ), 'Table'[Grade],, DESC, DENSE )
),
[index] = MAX ( 'Table'[Index] )
),
[rank]
)
)
Here is sample data, as per following table when department filtered with IT (by slicer), EmpID
107 would be Root Node based on ReportsTo_2
column. But visual won't work when 2 departments selected.
+-----------+------------+-------+---------------+---------+--------------+
| EmpID | ReportsTo | Grade | EmpDepartment | EmpName | ReportsTo_2
+-----------+------------+-------+---------------+---------+--------------+
| 101 | 107 | A1 | IT | Emp1 | 107
| 102 | 107 | A1 | IT | Emp2 | 107
| 103 | 107 | A1 | IT | Emp3 | 107
| 104 | 108 | A2 | Proc. | Emp1 | 108
| 105 | 108 | A2 | Proc. | Emp1 | 108
| 106 | 108 | A2 | Proc. | Emp1 | 108
| 107 | 109 | B1 | IT | Mgr1 |
| 108 | 109 | B1 | Proc. | Mgr2 |
| 109 | 110 | C2 | Management | Director|
| 110 | | D9 | Sr.Management | CEO |
+-----------+------------+-------+---------------+---------+--------------+
Expected Result: My idea is to get null
value in ReportsTo_2
column for highest Grade
within filtered data (filter by department).
Appreciated your advise to achieve this. Thanks
Additional info for clarification as requested in comments
Using following visuals:
Custom Visual 1
Custom Visual 2
Scenarios:
- When filtered with multiple departments (No Root Node available), if i use
ReportsTo_2
as parent it show the error "multiple Root Nodes": Image Link - When NO filter applied in departments: Image Link
Same Scenarios with Custom Visual 2:
Additional Note 2:
Main issue where i struck with, as Measure we can easily get expected result, but as Calculated Column same expression doesn't give expected result.
Image Link