TMDL Authoring
Expert guidance for authoring and editing TMDL (Tabular Model Definition Language) files directly in PBIP projects.
This skill is a last resort. Direct TMDL file editing lacks the validation, atomicity, and DAX query capabilities of the Tabular Editor CLI, Power BI MCP server, or the connect-pbid skill (TOM via PowerShell). Use those tools when available. TMDL editing is appropriate when:
- Working with PBIP files in a Git repo without Power BI Desktop open
- No Tabular Editor CLI or MCP server is installed
- Making quick text-level fixes (descriptions, format strings, display folders) where a full tool chain is overkill
Direct TMDL editing does not validate DAX syntax, check referential integrity, or verify that property values are valid. Errors will only surface when the model is next loaded in Power BI Desktop or deployed via XMLA. Use the pbip-validator agent to check TMDL files for syntax issues, indentation errors, and referential integrity before opening in PBI Desktop.
When to Use This Skill
Activate only when the Tabular Editor CLI, Power BI MCP server, or connect-pbid skill are not available, and tasks involve:
- Editing
.tmdl files directly (measures, columns, tables, relationships)
- Adding or modifying measure definitions in TMDL
- Adding descriptions to columns, measures, or tables
- Fixing
summarizeBy or formatString values
- Understanding TMDL syntax rules (indentation, quoting, property ordering)
- Writing multi-line DAX in TMDL format
- Understanding the difference between
/// descriptions and // comments
Critical
/// (triple-slash) sets the Description property on the object that immediately follows it. A /// line must be immediately followed by a declaration (measure, column, table, etc.); never by a blank line or another ///. Use // for regular comments.
- Indentation is semantic. TMDL uses whitespace indentation where depth equals nesting level (TMDL spec — Indentation). PBIP files use a single tab per level because Power BI Desktop and the TOM
TmdlSerializer default to IndentationMode.Tabs. Spaces are also valid (IndentationMode.Spaces, default 4 per level), but be consistent within a file; mixed or incorrect indentation will break the model. Properties of a table are indented one level; properties of a column (which belongs to a table) are indented two levels.
- Name quoting rules: Only quote names that contain spaces, special characters, or start with a digit. Simple names and underscore-prefixed names are unquoted. See the Name Quoting section for details.
- M expressions and tables share a namespace. A name declared by
expression <name> in expressions.tmdl and a name declared by table <name> in tables/*.tmdl collide; Power BI Desktop fails the load with 'duplicate member <name>'. Pick distinct names; the conventional fix is to suffix the M expression with Query or Source and have partitions reference it via source = #"<Name> Query". validate_pbip.py enforces this as an ERROR.
TMDL File Types
| File |
Contents |
Location |
model.tmdl |
Model configuration, ref table entries, query groups, annotations |
definition/ |
database.tmdl |
Compatibility level, model ID |
definition/ |
relationships.tmdl |
All relationships between tables |
definition/ |
expressions.tmdl |
Shared M expressions and parameters |
definition/ |
functions.tmdl |
DAX user-defined functions (reusable parameterized DAX) |
definition/ |
roles/<RoleName>.tmdl |
One file per security role (RLS filters, role members, OLS) |
definition/roles/ |
perspectives/<Name>.tmdl |
One file per perspective (object membership) |
definition/perspectives/ |
dataSources.tmdl |
Legacy data source definitions (if present) |
definition/ |
tables/<Name>.tmdl |
Table definition with columns, measures, hierarchies, partitions |
definition/tables/ |
cultures/<locale>.tmdl |
Linguistic metadata and translations |
definition/cultures/ |
Object Nesting Rules
Objects must be nested inside their correct parent. The validator enforces these rules:
| Object |
Allowed Parent(s) |
column, measure, hierarchy, partition, calculationGroup |
table |
level |
hierarchy |
calculationItem |
calculationGroup |
tablePermission |
role |
columnPermission |
tablePermission |
perspectiveTable |
perspective |
perspectiveColumn, perspectiveMeasure, perspectiveHierarchy |
perspectiveTable |
linguisticMetadata, translation |
cultureInfo |
dataAccessOptions |
model |
formatStringDefinition |
measure, calculationItem |
detailRowsDefinition |
measure, table |
alternateOf |
column |
member |
role |
annotation, extendedProperty |
any object (including queryGroup, function, member) |
ref |
model, table |
Root-level objects (indent 0 only): model, database, table, relationship, role, cultureInfo, perspective, dataSource, expression, queryGroup, function.
Syntax Rules
Indentation
TMDL uses whitespace indentation where depth equals nesting level. PBIP files use a single tab per level (the TOM TmdlSerializer default), so all examples below use tabs:
table Product // depth 0: top-level declaration
lineageTag: abc-123 // depth 1: table property
measure '# Products' = // depth 1: measure declaration
COUNTROWS ( // depth 3: DAX expression body (one deeper than properties)
VALUES ( Product[Name] ) // depth 3: continued
) // depth 3: continued
formatString: #,##0 // depth 2: measure property
displayFolder: Measures // depth 2: measure property
lineageTag: def-456 // depth 2: measure property
column 'Product Name' // depth 1: column declaration
dataType: string // depth 2: column property
lineageTag: ghi-789 // depth 2: column property
summarizeBy: none // depth 2: column property
sourceColumn: Product Name // depth 2: column property
annotation SummarizationSetBy = Automatic // depth 2: column annotation
Key rules:
- Use tabs in PBIP files (Power BI Desktop's default); see the Critical section above for the spaces alternative
- Table-level objects (columns, measures, hierarchies, partitions) are at depth 1
- Properties of those objects are at depth 2
- Multi-line DAX expression bodies are always 2 levels deeper than the enclosing declaration (depth 3 for measures/columns inside a table; depth 2 for top-level functions; depth 4 for calculationItems)
- Annotations are at the same depth as properties of their parent object, separated by a blank line
Descriptions (///)
Triple-slash sets the Description property on the next declaration. This is native TMDL syntax (not a Tabular Editor extension); the TMDL spec treats /// as first-class description support.
/// Count of distinct products in the current filter context.
measure '# Products' =
COUNTROWS ( VALUES ( Product[Product Name] ) )
formatString: #,##0
lineageTag: abc-123
Rules:
/// must be immediately followed by a declaration on the next line
- No blank line between
/// and the declaration
- Multiple
/// lines concatenate into a single description
/// applies to the next measure, column, table, hierarchy, or level
Common mistake:
// WRONG: blank line between /// and declaration
/// This is a description.
measure 'My Measure' = 1
// WRONG: /// used as a separator comment
///
measure 'My Measure' = 1
// RIGHT: /// immediately before declaration
/// This is a description.
measure 'My Measure' = 1
// RIGHT: // used for regular comments
// This is just a comment, not a description.
measure 'My Measure' = 1
Comments (//)
Double-slash is a regular comment with no semantic effect:
// This is a comment — it does not set any property
measure 'My Measure' = 1
Property Ordering
Properties should follow a consistent order, though TMDL is not strict about it. The conventional order is:
For columns: dataType, isHidden, isKey, displayFolder, lineageTag, summarizeBy, isNameInferred, sourceColumn, sortByColumn, then annotations.
For measures: DAX expression (on the = line or multi-line), formatString or formatStringDefinition, displayFolder, lineageTag, then annotations.
Name Quoting
When to Quote
Use single quotes around names that contain any of these characters:
- Spaces:
'Product Name'
- Dots:
'Sales.Amount'
- Equals:
'Price = Target'
- Colons:
'Date:Key'
- Single quotes (escape by doubling):
'Customer''s Name'
- Other special characters:
'Sales ($)', 'OTD % (Value)', '1) Selected Metric'
- Names starting with a digit:
'4) Selected Period'
When NOT to Quote
Do not quote names that are simple identifiers:
Product (simple word)
_Measures (underscore prefix, no spaces)
Date (simple word)
CgMetricQuantity (PascalCase, no spaces)
Examples
table Product // unquoted: simple name
table _Measures // unquoted: underscore prefix
table 'Budget Rate' // quoted: contains space
table 'Invoice Document Type' // quoted: contains spaces
table '1) Selected Metric' // quoted: starts with digit
table 'On-Time Delivery' // quoted: contains space
Column Definitions
For complete column examples (basic, hidden, key, sortByColumn, description), see references/tmdl-file-examples.md. For full property reference, see references/column-properties.md.
Key column pattern:
column 'Product Name'
dataType: string
displayFolder: 1. Product Hierarchy
lineageTag: abc-123
summarizeBy: none
sourceColumn: Product Name
annotation SummarizationSetBy = Automatic
Measure Definitions
Single-Line DAX
measure '# Products' = COUNTROWS ( VALUES ( Product[Product Name] ) )
formatString: #,##0
displayFolder: Measures
lineageTag: abc-123
Multi-Line DAX
Two syntaxes for multi-line DAX:
1. Indented block (most common) -- expression body indented two levels deeper than the declaration:
2. Triple-backtick block -- DAX enclosed in ``` fences, useful for expressions with complex indentation:
measure Percentage = ```
VAR _Total = CALCULATE( SUM ( 'Table'[Quantitative] ), REMOVEFILTERS ( ) )
RETURN
DIVIDE ( SUM ( 'Table'[Quantitative] ), _Total )
```
formatString: 0.0%;-0.0%;0.0%
lineageTag: abc-123
Indented block syntax (standard approach) -- indented two extra tabs from the measure's parent (table) level:
measure 'Actuals MTD' =
CALCULATE (
[Actuals],
CALCULATETABLE (
DATESMTD ( 'Date'[Date] ),
'Date'[IsDateInScope]
)
)
formatString: #,##0
displayFolder: 2. MTD\Actuals
lineageTag: abc-123
Measure with Description
/// Number of workdays elapsed month-to-date, considering only dates in scope.
measure '# Workdays MTD' =
CALCULATE(
MAX( 'Date'[Workdays MTD] ),
'Date'[IsDateInScope] = TRUE
)
formatString: #,##0
displayFolder: 5. Weekday / Workday\Measures\# Workdays
lineageTag: abc-123
Measure with formatStringDefinition (Dynamic Format)
measure 'Sales Target MTD vs. Actuals (%)' =
Comparison.RelativeToTarget (
[Actuals MTD],
[Sales Target MTD]
)
displayFolder: 2. MTD\Sales Target
lineageTag: abc-123
formatStringDefinition =
FormatString.Comparison.RelativeToTarget (
"SUFFIX",
1,
"ARROWS",
"",
""
)
Note: formatStringDefinition replaces formatString when the format is computed dynamically via a DAX expression (often a calculation group format function).
Other Object Types
For complete examples of calculated columns, roles (RLS/OLS), calculation groups, date table marking, hierarchies, partitions, relationships, shared expressions, and model configuration, see references/tmdl-file-examples.md.
Common Data Quality Patterns
summarizeBy Rules
| Column Type |
Correct summarizeBy |
Reason |
| Keys (surrogate/natural) |
none |
Keys are never aggregated |
| Attributes (names, codes, types) |
none |
Text attributes are never summed |
| Dates |
none |
Dates are never summed |
| Boolean flags |
none |
Flags are never summed |
| Additive numeric facts (amounts, quantities) |
sum |
Default aggregation is SUM |
| Non-additive numeric facts (rates, percentages) |
none |
Cannot be meaningfully summed |
Common fix pattern — changing summarizeBy: sum to summarizeBy: none for key columns:
// Before (wrong - key column should not sum)
column 'Customer Key'
dataType: int64
isHidden
lineageTag: abc-123
summarizeBy: sum
sourceColumn: Customer Key
// After (correct)
column 'Customer Key'
dataType: int64
isHidden
lineageTag: abc-123
summarizeBy: none
sourceColumn: Customer Key
formatString Patterns
| Data Type |
Pattern |
Example |
| Integer |
#,##0 |
1,234 |
| Decimal (2 places) |
#,##0.00 |
1,234.56 |
| Percentage |
#,##0% or 0.00% |
85% or 85.00% |
| Currency |
$#,##0.00 |
$1,234.56 |
| Date |
mm/dd/yyyy or dd/mm/yyyy |
01/15/2024 |
PBI_FormatHint Annotation
Power BI Desktop may add a PBI_FormatHint annotation alongside formatString:
column Amount
dataType: decimal
formatString: #,##0.00
lineageTag: abc-123
summarizeBy: sum
sourceColumn: Amount
annotation SummarizationSetBy = Automatic
annotation PBI_FormatHint = {"isGeneralNumber":true}
Do not fight this annotation. Power BI tooling re-adds it automatically. When setting a formatString, leave any existing PBI_FormatHint in place. If Power BI re-adds a removed PBI_FormatHint, accept it.
Quick Reference
Property Cheat Sheet
For the complete property reference for every object type, see references/object-properties.md.
| Object |
Property |
Values |
Notes |
| Column |
dataType |
string, int64, double, decimal, dateTime, boolean, binary, unknown, variant, automatic |
Required for data columns |
| Column |
summarizeBy |
default, none, sum, min, max, count, average, distinctCount |
Use none for keys/attributes |
| Column |
type |
data, calculated, rowNumber, calculatedTableColumn |
Column type variant |
| Column |
isHidden |
(flag, no value) |
Boolean flags: write the keyword alone on its own line |
| Column |
isKey |
(flag, no value) |
Marks the column as the table's key |
| Column |
isNullable |
(flag, no value) |
Column allows nulls |
| Column |
isUnique |
(flag, no value) |
Column values are unique |
| Column |
isNameInferred |
(flag, no value) |
Name inferred from source |
| Column |
isDefaultLabel |
(flag, no value) |
Default label for the table |
| Column |
isDefaultImage |
(flag, no value) |
Default image for the table |
| Column |
isDataTypeInferred |
(flag, no value) |
Data type inferred from source |
| Column |
isAvailableInMdx |
(flag, no value) |
Available in MDX queries |
| Column |
keepUniqueRows |
(flag, no value) |
Keep unique rows |
| Column |
encodingHint |
default, hash, value |
Storage encoding hint |
| Column |
alignment |
default, left, right, center |
Column alignment |
| Column |
displayFolder |
folder path string |
Use \ for nesting: 1. Year\Quarter |
| Column |
sourceColumn |
source column name |
Must match the Power Query output column |
| Column |
sortByColumn |
column name reference |
Column to sort by (e.g., month name sorted by month number) |
| Column |
expression |
DAX expression |
For calculated columns |
| Measure |
formatString |
format pattern |
e.g., #,##0, 0.00% |
| Measure |
displayFolder |
folder path string |
Use \ for nesting |
| Measure |
formatStringDefinition |
DAX expression block |
Dynamic format string (replaces formatString) |
| Measure |
isHidden |
(flag, no value) |
Hide the measure |
| Measure |
isSimpleMeasure |
(flag, no value) |
Simple implicit-style measure |
| Measure |
dataCategory |
string |
Semantic data category |
| Partition |
mode |
import, directQuery, default, push, dual, directLake |
Storage mode |
| Partition |
sourceType |
query, calculated, none, m, entity, policyRange, calculationGroup, inferred |
Source type |
| Relationship |
crossFilteringBehavior |
oneDirection, bothDirections, automatic |
Cross-filter direction |
| Relationship |
securityFilteringBehavior |
oneDirection, bothDirections, none |
RLS filter direction |
| Relationship |
fromCardinality / toCardinality |
none, one, many |
Cardinality ends |
| Relationship |
isActive |
(flag, no value) |
Active relationship |
| Role |
modelPermission |
none, read, readRefresh, refresh, administrator |
Role permission level |
| Model |
discourageImplicitMeasures |
(flag, no value) |
Disables implicit measures |
| Model |
defaultPowerBIDataSourceVersion |
powerBI_V1, powerBI_V2, powerBI_V3 |
PBI data source version |
| Model |
directLakeBehavior |
automatic, directLakeOnly, directQueryOnly |
Direct Lake mode |
| All |
lineageTag |
GUID |
Unique identifier, do not change existing values |
Indentation Depth Summary
Rule: a multi-line DAX body is always 2 levels deeper than its enclosing object declaration.
| Context |
Depth |
Tabs |
Top-level declaration (table, relationship, expression) |
0 |
0 |
| Table properties, column/measure/hierarchy declarations |
1 |
1 |
| Column/measure properties, hierarchy levels |
2 |
2 |
| DAX body for measure/column declared at depth 1 (inside table) |
3 |
3 |
| Level properties |
3 |
3 |
DAX body for top-level function declared at depth 0 |
2 |
2 |
calculationItem inside calculationGroup (depth 1) |
2 |
2 |
DAX body for calculationItem at depth 2 |
4 |
4 |
Additional Resources
Reference Files
references/object-properties.md - Complete property reference for all 30+ TMDL object types with valid enum values for every property type (dataType, summarizeBy, modeType, crossFilteringBehavior, etc.)
references/column-properties.md - Column-specific property guide with summarizeBy rules, formatString patterns, PBI_FormatHint behavior
references/naming-conventions.md - SQLBI naming conventions, display folder conventions, measure table conventions, and calculation group naming
references/bim-to-tmdl.md - Converting between model.bim (TMSL) and definition/ (TMDL) via Tabular Editor CLI or TOM TmdlSerializer
references/tmdl-file-examples.md - Complete examples for every TMDL file type (model, database, expressions, relationships, roles, perspectives, tables, cultures) including backtick-enclosed expressions, field parameters, calculation groups, and date tables
Fetching Docs
To retrieve current TMDL reference docs, use microsoft_docs_search + microsoft_docs_fetch (MCP) if available, otherwise mslearn search + mslearn fetch (CLI). Search based on the user's request and run multiple searches as needed to ensure sufficient context before proceeding.
Example Model
examples/SpaceParts.SemanticModel/ -- Complete real-world TMDL model (SpaceParts) with 40 tables, 152 measures, 8 calculation groups, 8 RLS roles, 2 perspectives, DAX UDFs (functions.tmdl), shared M expressions, relationships, and cultures. Covers every TMDL file type. Key files to study:
definition/functions.tmdl -- DAX user-defined functions with parameters, types, and multi-line expressions
definition/tables/Z04CG1 - Time Intelligence.tmdl -- Calculation group with triple-backtick DAX
definition/tables/__Measures.tmdl -- Measures table with calculation group references
definition/tables/Invoices.tmdl -- Large fact table (51 measures, 18 columns)
definition/tables/Date.tmdl -- Calculated date table with 42 columns
definition/roles/Account Managers.tmdl -- RLS role with DAX filter expression
definition/relationships.tmdl -- 27 relationships including inactive
definition/expressions.tmdl -- Shared M/Power Query expressions and parameters
definition/perspectives/Measure Selection.tmdl -- Perspective definition
External References
Source: data-goblin/power-bi-agentic-development → plugins/pbip/skills/tmdl/SKILL.md
1---2name: tmdl3description: Direct TMDL file authoring and BIM-to-TMDL conversion for semantic models in PBIP projects. Automatically invoke when the user asks to "edit TMDL", "add a measure in TMDL", "TMDL syntax", "fix formatString", "fix summarizeBy", "TMDL indentation", "convert BIM to TMDL", "add a column description", "create a calculated column in TMDL", or mentions .tmdl file editing or BIM-to-TMDL migration.4---5# TMDL Authoring67Expert guidance for authoring and editing TMDL (Tabular Model Definition Language) files directly in PBIP projects.89> **This skill is a last resort.** Direct TMDL file editing lacks the validation, atomicity, and DAX query capabilities of the Tabular Editor CLI, Power BI MCP server, or the `connect-pbid` skill (TOM via PowerShell). Use those tools when available. TMDL editing is appropriate when:10>11> - Working with PBIP files in a Git repo without Power BI Desktop open12> - No Tabular Editor CLI or MCP server is installed13> - Making quick text-level fixes (descriptions, format strings, display folders) where a full tool chain is overkill14>15> Direct TMDL editing does not validate DAX syntax, check referential integrity, or verify that property values are valid. Errors will only surface when the model is next loaded in Power BI Desktop or deployed via XMLA. Use the **`pbip-validator`** agent to check TMDL files for syntax issues, indentation errors, and referential integrity before opening in PBI Desktop.1617## When to Use This Skill1819Activate only when the Tabular Editor CLI, Power BI MCP server, or `connect-pbid` skill are not available, and tasks involve:2021- Editing `.tmdl` files directly (measures, columns, tables, relationships)22- Adding or modifying measure definitions in TMDL23- Adding descriptions to columns, measures, or tables24- Fixing `summarizeBy` or `formatString` values25- Understanding TMDL syntax rules (indentation, quoting, property ordering)26- Writing multi-line DAX in TMDL format27- Understanding the difference between `///` descriptions and `//` comments2829## Critical3031- **`///` (triple-slash) sets the `Description` property** on the object that immediately follows it. A `///` line must be immediately followed by a declaration (`measure`, `column`, `table`, etc.); never by a blank line or another `///`. Use `//` for regular comments.32- **Indentation is semantic.** TMDL uses whitespace indentation where depth equals nesting level ([TMDL spec — Indentation](https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-overview#indentation)). PBIP files use a single tab per level because Power BI Desktop and the TOM `TmdlSerializer` default to `IndentationMode.Tabs`. Spaces are also valid (`IndentationMode.Spaces`, default 4 per level), but be consistent within a file; mixed or incorrect indentation will break the model. Properties of a table are indented one level; properties of a column (which belongs to a table) are indented two levels.33- **Name quoting rules:** Only quote names that contain spaces, special characters, or start with a digit. Simple names and underscore-prefixed names are unquoted. See the Name Quoting section for details.34- **M expressions and tables share a namespace.** A name declared by `expression <name>` in `expressions.tmdl` and a name declared by `table <name>` in `tables/*.tmdl` collide; Power BI Desktop fails the load with `'duplicate member <name>'`. Pick distinct names; the conventional fix is to suffix the M expression with ` Query` or ` Source` and have partitions reference it via `source = #"<Name> Query"`. `validate_pbip.py` enforces this as an ERROR.3536## TMDL File Types3738| File | Contents | Location |39|------|----------|----------|40| `model.tmdl` | Model configuration, `ref table` entries, query groups, annotations | `definition/` |41| `database.tmdl` | Compatibility level, model ID | `definition/` |42| `relationships.tmdl` | All relationships between tables | `definition/` |43| `expressions.tmdl` | Shared M expressions and parameters | `definition/` |44| `functions.tmdl` | DAX user-defined functions (reusable parameterized DAX) | `definition/` |45| `roles/<RoleName>.tmdl` | One file per security role (RLS filters, role members, OLS) | `definition/roles/` |46| `perspectives/<Name>.tmdl` | One file per perspective (object membership) | `definition/perspectives/` |47| `dataSources.tmdl` | Legacy data source definitions (if present) | `definition/` |48| `tables/<Name>.tmdl` | Table definition with columns, measures, hierarchies, partitions | `definition/tables/` |49| `cultures/<locale>.tmdl` | Linguistic metadata and translations | `definition/cultures/` |5051## Object Nesting Rules5253Objects must be nested inside their correct parent. The validator enforces these rules:5455| Object | Allowed Parent(s) |56|--------|-------------------|57| `column`, `measure`, `hierarchy`, `partition`, `calculationGroup` | `table` |58| `level` | `hierarchy` |59| `calculationItem` | `calculationGroup` |60| `tablePermission` | `role` |61| `columnPermission` | `tablePermission` |62| `perspectiveTable` | `perspective` |63| `perspectiveColumn`, `perspectiveMeasure`, `perspectiveHierarchy` | `perspectiveTable` |64| `linguisticMetadata`, `translation` | `cultureInfo` |65| `dataAccessOptions` | `model` |66| `formatStringDefinition` | `measure`, `calculationItem` |67| `detailRowsDefinition` | `measure`, `table` |68| `alternateOf` | `column` |69| `member` | `role` |70| `annotation`, `extendedProperty` | any object (including `queryGroup`, `function`, `member`) |71| `ref` | `model`, `table` |7273Root-level objects (indent 0 only): `model`, `database`, `table`, `relationship`, `role`, `cultureInfo`, `perspective`, `dataSource`, `expression`, `queryGroup`, `function`.7475## Syntax Rules7677### Indentation7879TMDL uses **whitespace indentation** where depth equals nesting level. PBIP files use a single tab per level (the TOM `TmdlSerializer` default), so all examples below use tabs:8081```tmdl82table Product // depth 0: top-level declaration83 lineageTag: abc-123 // depth 1: table property8485 measure '# Products' = // depth 1: measure declaration86 COUNTROWS ( // depth 3: DAX expression body (one deeper than properties)87 VALUES ( Product[Name] ) // depth 3: continued88 ) // depth 3: continued89 formatString: #,##0 // depth 2: measure property90 displayFolder: Measures // depth 2: measure property91 lineageTag: def-456 // depth 2: measure property9293 column 'Product Name' // depth 1: column declaration94 dataType: string // depth 2: column property95 lineageTag: ghi-789 // depth 2: column property96 summarizeBy: none // depth 2: column property97 sourceColumn: Product Name // depth 2: column property9899 annotation SummarizationSetBy = Automatic // depth 2: column annotation100```101102**Key rules:**103- Use tabs in PBIP files (Power BI Desktop's default); see the Critical section above for the spaces alternative104- Table-level objects (columns, measures, hierarchies, partitions) are at depth 1105- Properties of those objects are at depth 2106- Multi-line DAX expression bodies are always **2 levels deeper than the enclosing declaration** (depth 3 for measures/columns inside a table; depth 2 for top-level functions; depth 4 for calculationItems)107- Annotations are at the same depth as properties of their parent object, separated by a blank line108109### Descriptions (`///`)110111Triple-slash sets the `Description` property on the **next** declaration. This is native TMDL syntax (not a Tabular Editor extension); the TMDL spec treats `///` as first-class description support.112113```tmdl114/// Count of distinct products in the current filter context.115measure '# Products' =116 COUNTROWS ( VALUES ( Product[Product Name] ) )117 formatString: #,##0118 lineageTag: abc-123119```120121**Rules:**122- `///` must be immediately followed by a declaration on the next line123- No blank line between `///` and the declaration124- Multiple `///` lines concatenate into a single description125- `///` applies to the next `measure`, `column`, `table`, `hierarchy`, or `level`126127**Common mistake:**128```tmdl129// WRONG: blank line between /// and declaration130/// This is a description.131132measure 'My Measure' = 1133134// WRONG: /// used as a separator comment135///136measure 'My Measure' = 1137138// RIGHT: /// immediately before declaration139/// This is a description.140measure 'My Measure' = 1141142// RIGHT: // used for regular comments143// This is just a comment, not a description.144measure 'My Measure' = 1145```146147### Comments (`//`)148149Double-slash is a regular comment with no semantic effect:150151```tmdl152// This is a comment — it does not set any property153measure 'My Measure' = 1154```155156### Property Ordering157158Properties should follow a consistent order, though TMDL is not strict about it. The conventional order is:159160**For columns:** `dataType`, `isHidden`, `isKey`, `displayFolder`, `lineageTag`, `summarizeBy`, `isNameInferred`, `sourceColumn`, `sortByColumn`, then annotations.161162**For measures:** DAX expression (on the `=` line or multi-line), `formatString` or `formatStringDefinition`, `displayFolder`, `lineageTag`, then annotations.163164## Name Quoting165166### When to Quote167168Use single quotes around names that contain any of these characters:169- Spaces: `'Product Name'`170- Dots: `'Sales.Amount'`171- Equals: `'Price = Target'`172- Colons: `'Date:Key'`173- Single quotes (escape by doubling): `'Customer''s Name'`174- Other special characters: `'Sales ($)'`, `'OTD % (Value)'`, `'1) Selected Metric'`175- Names starting with a digit: `'4) Selected Period'`176177### When NOT to Quote178179Do not quote names that are simple identifiers:180- `Product` (simple word)181- `_Measures` (underscore prefix, no spaces)182- `Date` (simple word)183- `CgMetricQuantity` (PascalCase, no spaces)184185### Examples186187```tmdl188table Product // unquoted: simple name189table _Measures // unquoted: underscore prefix190table 'Budget Rate' // quoted: contains space191table 'Invoice Document Type' // quoted: contains spaces192table '1) Selected Metric' // quoted: starts with digit193table 'On-Time Delivery' // quoted: contains space194```195196## Column Definitions197198For complete column examples (basic, hidden, key, sortByColumn, description), see **`references/tmdl-file-examples.md`**. For full property reference, see **`references/column-properties.md`**.199200Key column pattern:201202```tmdl203column 'Product Name'204 dataType: string205 displayFolder: 1. Product Hierarchy206 lineageTag: abc-123207 summarizeBy: none208 sourceColumn: Product Name209210 annotation SummarizationSetBy = Automatic211```212213## Measure Definitions214215### Single-Line DAX216217```tmdl218measure '# Products' = COUNTROWS ( VALUES ( Product[Product Name] ) )219 formatString: #,##0220 displayFolder: Measures221 lineageTag: abc-123222```223224### Multi-Line DAX225226Two syntaxes for multi-line DAX:227228**1. Indented block** (most common) -- expression body indented two levels deeper than the declaration:229230**2. Triple-backtick block** -- DAX enclosed in `` ``` `` fences, useful for expressions with complex indentation:231232```tmdl233measure Percentage = ```234 VAR _Total = CALCULATE( SUM ( 'Table'[Quantitative] ), REMOVEFILTERS ( ) )235 RETURN236 DIVIDE ( SUM ( 'Table'[Quantitative] ), _Total )237 ```238 formatString: 0.0%;-0.0%;0.0%239 lineageTag: abc-123240```241242**Indented block syntax** (standard approach) -- indented two extra tabs from the measure's parent (table) level:243244```tmdl245measure 'Actuals MTD' =246 CALCULATE (247 [Actuals],248 CALCULATETABLE (249 DATESMTD ( 'Date'[Date] ),250 'Date'[IsDateInScope]251 )252 )253 formatString: #,##0254 displayFolder: 2. MTD\Actuals255 lineageTag: abc-123256```257258### Measure with Description259260```tmdl261/// Number of workdays elapsed month-to-date, considering only dates in scope.262measure '# Workdays MTD' =263 CALCULATE(264 MAX( 'Date'[Workdays MTD] ),265 'Date'[IsDateInScope] = TRUE266 )267 formatString: #,##0268 displayFolder: 5. Weekday / Workday\Measures\# Workdays269 lineageTag: abc-123270```271272### Measure with formatStringDefinition (Dynamic Format)273274```tmdl275measure 'Sales Target MTD vs. Actuals (%)' =276 Comparison.RelativeToTarget (277 [Actuals MTD],278 [Sales Target MTD]279 )280 displayFolder: 2. MTD\Sales Target281 lineageTag: abc-123282283 formatStringDefinition =284 FormatString.Comparison.RelativeToTarget (285 "SUFFIX",286 1,287 "ARROWS",288 "",289 ""290 )291```292293**Note:** `formatStringDefinition` replaces `formatString` when the format is computed dynamically via a DAX expression (often a calculation group format function).294295## Other Object Types296297For complete examples of calculated columns, roles (RLS/OLS), calculation groups, date table marking, hierarchies, partitions, relationships, shared expressions, and model configuration, see **`references/tmdl-file-examples.md`**.298299300## Common Data Quality Patterns301302### summarizeBy Rules303304| Column Type | Correct `summarizeBy` | Reason |305|-------------|----------------------|--------|306| Keys (surrogate/natural) | `none` | Keys are never aggregated |307| Attributes (names, codes, types) | `none` | Text attributes are never summed |308| Dates | `none` | Dates are never summed |309| Boolean flags | `none` | Flags are never summed |310| Additive numeric facts (amounts, quantities) | `sum` | Default aggregation is SUM |311| Non-additive numeric facts (rates, percentages) | `none` | Cannot be meaningfully summed |312313**Common fix pattern** — changing `summarizeBy: sum` to `summarizeBy: none` for key columns:314315```tmdl316// Before (wrong - key column should not sum)317column 'Customer Key'318 dataType: int64319 isHidden320 lineageTag: abc-123321 summarizeBy: sum322 sourceColumn: Customer Key323324// After (correct)325column 'Customer Key'326 dataType: int64327 isHidden328 lineageTag: abc-123329 summarizeBy: none330 sourceColumn: Customer Key331```332333### formatString Patterns334335| Data Type | Pattern | Example |336|-----------|---------|---------|337| Integer | `#,##0` | 1,234 |338| Decimal (2 places) | `#,##0.00` | 1,234.56 |339| Percentage | `#,##0%` or `0.00%` | 85% or 85.00% |340| Currency | `$#,##0.00` | $1,234.56 |341| Date | `mm/dd/yyyy` or `dd/mm/yyyy` | 01/15/2024 |342343### PBI_FormatHint Annotation344345Power BI Desktop may add a `PBI_FormatHint` annotation alongside `formatString`:346347```tmdl348column Amount349 dataType: decimal350 formatString: #,##0.00351 lineageTag: abc-123352 summarizeBy: sum353 sourceColumn: Amount354355 annotation SummarizationSetBy = Automatic356357 annotation PBI_FormatHint = {"isGeneralNumber":true}358```359360**Do not fight this annotation.** Power BI tooling re-adds it automatically. When setting a `formatString`, leave any existing `PBI_FormatHint` in place. If Power BI re-adds a removed `PBI_FormatHint`, accept it.361362363## Quick Reference364365### Property Cheat Sheet366367For the complete property reference for every object type, see **`references/object-properties.md`**.368369| Object | Property | Values | Notes |370|--------|----------|--------|-------|371| Column | `dataType` | `string`, `int64`, `double`, `decimal`, `dateTime`, `boolean`, `binary`, `unknown`, `variant`, `automatic` | Required for data columns |372| Column | `summarizeBy` | `default`, `none`, `sum`, `min`, `max`, `count`, `average`, `distinctCount` | Use `none` for keys/attributes |373| Column | `type` | `data`, `calculated`, `rowNumber`, `calculatedTableColumn` | Column type variant |374| Column | `isHidden` | (flag, no value) | Boolean flags: write the keyword alone on its own line |375| Column | `isKey` | (flag, no value) | Marks the column as the table's key |376| Column | `isNullable` | (flag, no value) | Column allows nulls |377| Column | `isUnique` | (flag, no value) | Column values are unique |378| Column | `isNameInferred` | (flag, no value) | Name inferred from source |379| Column | `isDefaultLabel` | (flag, no value) | Default label for the table |380| Column | `isDefaultImage` | (flag, no value) | Default image for the table |381| Column | `isDataTypeInferred` | (flag, no value) | Data type inferred from source |382| Column | `isAvailableInMdx` | (flag, no value) | Available in MDX queries |383| Column | `keepUniqueRows` | (flag, no value) | Keep unique rows |384| Column | `encodingHint` | `default`, `hash`, `value` | Storage encoding hint |385| Column | `alignment` | `default`, `left`, `right`, `center` | Column alignment |386| Column | `displayFolder` | folder path string | Use `\` for nesting: `1. Year\Quarter` |387| Column | `sourceColumn` | source column name | Must match the Power Query output column |388| Column | `sortByColumn` | column name reference | Column to sort by (e.g., month name sorted by month number) |389| Column | `expression` | DAX expression | For calculated columns |390| Measure | `formatString` | format pattern | e.g., `#,##0`, `0.00%` |391| Measure | `displayFolder` | folder path string | Use `\` for nesting |392| Measure | `formatStringDefinition` | DAX expression block | Dynamic format string (replaces `formatString`) |393| Measure | `isHidden` | (flag, no value) | Hide the measure |394| Measure | `isSimpleMeasure` | (flag, no value) | Simple implicit-style measure |395| Measure | `dataCategory` | string | Semantic data category |396| Partition | `mode` | `import`, `directQuery`, `default`, `push`, `dual`, `directLake` | Storage mode |397| Partition | `sourceType` | `query`, `calculated`, `none`, `m`, `entity`, `policyRange`, `calculationGroup`, `inferred` | Source type |398| Relationship | `crossFilteringBehavior` | `oneDirection`, `bothDirections`, `automatic` | Cross-filter direction |399| Relationship | `securityFilteringBehavior` | `oneDirection`, `bothDirections`, `none` | RLS filter direction |400| Relationship | `fromCardinality` / `toCardinality` | `none`, `one`, `many` | Cardinality ends |401| Relationship | `isActive` | (flag, no value) | Active relationship |402| Role | `modelPermission` | `none`, `read`, `readRefresh`, `refresh`, `administrator` | Role permission level |403| Model | `discourageImplicitMeasures` | (flag, no value) | Disables implicit measures |404| Model | `defaultPowerBIDataSourceVersion` | `powerBI_V1`, `powerBI_V2`, `powerBI_V3` | PBI data source version |405| Model | `directLakeBehavior` | `automatic`, `directLakeOnly`, `directQueryOnly` | Direct Lake mode |406| All | `lineageTag` | GUID | Unique identifier, do not change existing values |407408### Indentation Depth Summary409410**Rule: a multi-line DAX body is always 2 levels deeper than its enclosing object declaration.**411412| Context | Depth | Tabs |413|---------|-------|------|414| Top-level declaration (`table`, `relationship`, `expression`) | 0 | 0 |415| Table properties, column/measure/hierarchy declarations | 1 | 1 |416| Column/measure properties, hierarchy levels | 2 | 2 |417| DAX body for measure/column declared at depth 1 (inside table) | 3 | 3 |418| Level properties | 3 | 3 |419| DAX body for top-level `function` declared at depth 0 | 2 | 2 |420| `calculationItem` inside `calculationGroup` (depth 1) | 2 | 2 |421| DAX body for `calculationItem` at depth 2 | 4 | 4 |422423## Additional Resources424425### Reference Files426427- **`references/object-properties.md`** - Complete property reference for all 30+ TMDL object types with valid enum values for every property type (dataType, summarizeBy, modeType, crossFilteringBehavior, etc.)428- **`references/column-properties.md`** - Column-specific property guide with `summarizeBy` rules, `formatString` patterns, `PBI_FormatHint` behavior429- **`references/naming-conventions.md`** - SQLBI naming conventions, display folder conventions, measure table conventions, and calculation group naming430- **`references/bim-to-tmdl.md`** - Converting between `model.bim` (TMSL) and `definition/` (TMDL) via Tabular Editor CLI or TOM TmdlSerializer431- **`references/tmdl-file-examples.md`** - Complete examples for every TMDL file type (model, database, expressions, relationships, roles, perspectives, tables, cultures) including backtick-enclosed expressions, field parameters, calculation groups, and date tables432433### Fetching Docs434435To retrieve current TMDL reference docs, use `microsoft_docs_search` + `microsoft_docs_fetch` (MCP) if available, otherwise `mslearn search` + `mslearn fetch` (CLI). Search based on the user's request and run multiple searches as needed to ensure sufficient context before proceeding.436437### Example Model438439- **`examples/SpaceParts.SemanticModel/`** -- Complete real-world TMDL model (SpaceParts) with 40 tables, 152 measures, 8 calculation groups, 8 RLS roles, 2 perspectives, DAX UDFs (functions.tmdl), shared M expressions, relationships, and cultures. Covers every TMDL file type. Key files to study:440 - `definition/functions.tmdl` -- DAX user-defined functions with parameters, types, and multi-line expressions441 - `definition/tables/Z04CG1 - Time Intelligence.tmdl` -- Calculation group with triple-backtick DAX442 - `definition/tables/__Measures.tmdl` -- Measures table with calculation group references443 - `definition/tables/Invoices.tmdl` -- Large fact table (51 measures, 18 columns)444 - `definition/tables/Date.tmdl` -- Calculated date table with 42 columns445 - `definition/roles/Account Managers.tmdl` -- RLS role with DAX filter expression446 - `definition/relationships.tmdl` -- 27 relationships including inactive447 - `definition/expressions.tmdl` -- Shared M/Power Query expressions and parameters448 - `definition/perspectives/Measure Selection.tmdl` -- Perspective definition449450### External References451452- [TMDL overview (Microsoft Learn)](https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-overview)453- [TMDL syntax reference (Microsoft Learn)](https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-how-to)454- [SQLBI naming conventions](https://www.sqlbi.com/articles/rules-of-the-game-how-to-name-things-in-your-data-model/)455456---457458**Source:** [`data-goblin/power-bi-agentic-development`](https://github.com/data-goblin/power-bi-agentic-development) → `plugins/pbip/skills/tmdl/SKILL.md`