Governed model tests
A governed model is a testable contract
A governed semantic model combines a clear fact grain, measures, security and operational ownership. The aim is not just a correct total under an administrator account: a regional viewer must see the correct restricted total, and an unmapped identity must see no facts. This capstone reuses advanced DAX, star schema and RLS skills from Chapters 19, 31, 32 and 41–44. Use labs/governed-model-capstone/ for the synthetic data and candidate definitions. All native examples are staged, not executed.
Model and identity setup
Import the baseline, Region and Entitlements CSVs. Follow model-dictionary.md for the 2025 Date table, types and relationships. One sale per SaleKey; Region and Date have unique keys and one-to-many single-direction paths to Sales. Entitlements is disconnected and filtered by its own role expression; the Region role checks the current principal against it. Both viewers are assigned the same read-only role. The unmapped test identity is assigned that role but has no mapping. Use role-definitions.md; never grant model Write to a test viewer. Date labels are not sensitive. Exclude source-only DiagnosticToken from the lean model.
Worked example 1 — reconcile the unrestricted baseline
Create the explicit measures from measures.dax one at a time. On an unrestricted local author baseline, run this DAX query (expected output, native NOT RUN):
EVALUATEROW("Revenue", [Revenue], "Profit", [Gross Profit], "Margin", [Gross Margin], "Rows", [Visible Sales])Eight sales total USD 550; cost is USD 345, profit USD 205 and margin 205/550 = 37.27% rounded. The ratio is calculated from totals, not the mean of region margins. January is 250 and February is 300. query-months.dax uses the explicit Revenue YTD measure; expected January YTD 250, February YTD 550. Equivalent calculation-group item for revenue only: IF(ISSELECTEDMEASURE([Revenue]), CALCULATE(SELECTEDMEASURE(), DATESYTD('Date'[Date])), SELECTEDMEASURE()). Use the explicit measure as the required baseline; optional calculation group requires native validation.
Worked example 2 — negative role tests
Under North Viewer the same query predicts four rows, revenue 300, profit 115 and margin 38.33%; South predicts four rows, revenue 250, profit 90 and margin 36%. The unmapped test identity predicts 0 rows and BLANK monetary and margin measures. A North Viewer filtering South must also get no rows. Run query-regions.dax separately under each actual approved Viewer: only the permitted region should appear. ROW yields a scalar-result row even when there are no visible facts; SUMMARIZECOLUMNS with only blank expressions can omit a group. Use independent expected SQL values, not privileged author results, as the test oracle.
Mistakes that invalidate signoff
Hiding a table is not object security; direct source access is a separate authorization path. Extra roles can broaden allowed rows, and write-capable workspace roles are not restricted by RLS in the same way as Viewers. A visual filter is not a security boundary. Do not add a broad fallback for a missing UPN. Validate mapping, entitlements visibility, actual effective identity, region query and permitted export in an approved test workspace before releasing. The offline oracle tests expected row sets only.
Practice and references
Calculate North and South January and February revenue, costs, margins and YTD; include cross-region and no-map cases. Record expected vs observed separately in the worksheet. Reference: star schema, RLS, RLS guidance, DAX queries, calculation groups, SUMMARIZECOLUMNS.