Forum Discussion
How to detect drill mode
Hi alexpokerface ,
As dm-p said there is no simple straight forward method to check this. However, you can do try the following, all inside update():
1. dataView.metadata.dataRoles.drillableRoles β a map of role name β the DrillType[] currently available for it. When Drill Up is available for a role, the user has drilled down at least one level, which is the reliable "am I in a drilled-down state" signal:
import powerbi from "powerbi-visuals-api"; import DrillType = powerbi.DrillType; public update(options: powerbi.extensibility.visual.VisualUpdateOptionsπ void { const dataRoles = options.dataViews?.[0]?.metadata?.dataRoles; const available = dataRoles?.drillableRoles?.["category"] ?? []; // role name from capabilities "drilldown".roles const isDrilledDown = available.indexOf(DrillType.Up) >= 0; // Drill Up exists => below the top level const canDrillDown = available.indexOf(DrillType.Down) >= 0; // more levels below const drillDisabled = dataRoles?.isDrillDisabled === true; // drilling currently turned off }
2. After any drill, Power BI just calls update() again with a new DataView. Read the level from the data β categorical: the number of categorical.categories and each categories[i].source.displayName (e.g., Year β Quarter β Month); matrix: the depth of matrix.rows.levels and each node's level. Note the category value type can change per level (Date at the top, string lower down), so guard with categories[i].source.type before parsing.
3. To drive drilling from your own UX (e.g., double-click to drill down), call host.drill(args) (API 4.7.0+), and optionally host.setCanDrill(true/false) (5.7.0+) to enable/disable it at runtime.
Good luck,
Asaf.
References
- The Drilldown API in Power BI visuals β documents the exact drillableRoles['...'].indexOf(powerbi.DrillType.Down) pattern and host.drill()
- Add drill-down support in Power BI visuals
- The dynamic drill-down API in Power BI visuals