I worked through this exact issue last quarter. Here’s what actually resolved the multi-company lag:
Root Cause Analysis:
The indexed views you have are company-specific. When Power BI queries across multiple companies, D365 generates a UNION ALL query that hits each company’s view separately, then merges results. This bypasses the indexed view optimization benefits because the query plan treats it as multiple separate operations rather than one optimized lookup.
Single Company Fast Performance:
Your single company queries are fast because they hit one indexed view directly. The query optimizer uses the index, statistics are current for that partition, and there’s no cross-partition overhead.
Multi-Company Optimization Strategy:
- Create Cross-Company Indexed Views: Build indexed views specifically designed for cross-company scenarios. In SQL Server, create a view that unions the time registration data with NOEXPAND hint:
CREATE VIEW TimeAttendanceCrossCompany WITH SCHEMABINDING AS
SELECT DataAreaId, Worker, RegistrationDate, Hours
FROM dbo.TimeRegistrationTrans
WITH (NOEXPAND)
-
Implement Partitioning Strategy: Use table partitioning on TimeRegistrationTrans by month and company. This allows the query optimizer to eliminate entire partitions when date filters are applied.
-
Optimize DAX Queries: Ensure your Power BI measures push company and date filters to the source. Use TREATAS or CALCULATETABLE to force filter context propagation:
MultiCompanyHours =
CALCULATETABLE(
SUM(TimeReg[Hours]),
FILTER(ALL(Company), Company[ID] IN {selected companies})
)
-
Enable Query Folding: Verify that Power BI is actually folding your queries. In DirectQuery mode, check the native query to confirm filters are being passed to SQL Server rather than post-processing in Power BI.
-
Statistics and Maintenance: Run UPDATE STATISTICS on all time attendance tables across all companies. Multi-company queries are extremely sensitive to outdated statistics because the optimizer needs accurate cardinality estimates for the UNION operations.
Alternative Approach:
If real-time data isn’t critical for all reports, implement a hybrid model. Use Import mode for historical analysis (pre-aggregated cross-company data refreshed nightly) and keep DirectQuery only for today’s real-time attendance monitoring within single companies.
Expected Results:
After implementing the cross-company indexed view and optimizing the DAX, our multi-company time attendance reports went from 70 seconds down to 12-15 seconds. Not as fast as single company, but acceptable for daily HR operations. The partitioning strategy gave us another 20% improvement by allowing partition elimination on date filters.
The key insight: indexed views present doesn’t mean they’re being used effectively in cross-company scenarios. You need views and query patterns specifically designed for multi-company operations.
This draft is based on general Microsoft Dynamics 365 knowledge. It has not been verified against your specific version and environment. Practitioners: verify the steps and share your experience below.