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."4category: engineering-core5source_repo: data-goblin/power-bi-agentic-development6source_path: "plugins/pbip/skills/tmdl/SKILL.md"7source_url: https://github.com/data-goblin/power-bi-agentic-development/blob/HEAD/plugins/pbip/skills/tmdl/SKILL.md8metadata:9 source: https://skillmd.com/skills/thedixitjain/tmdl10---1112# TMDL Authoring1314Expert guidance for authoring and editing TMDL (Tabular Model Definition Language) files directly in PBIP projects.1516> **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:17>18> - Working with PBIP files in a Git repo without Power BI Desktop open19> - No Tabular Editor CLI or MCP server is installed20> - Making quick text-level fixes (descriptions, format strings, display folders) where a full tool chain is overkill21>22> 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.2324## When to Use This Skill2526Activate only when the Tabular Editor CLI, Power BI MCP server, or `connect-pbid` skill are not available, and tasks involve:2728- Editing `.tmdl` files directly (measures, columns, tables, relationships)29- Adding or modifying measure definitions in TMDL30- Adding descriptions to columns, measures, or tables31- Fixing `summarizeBy` or `formatString` values32- Understanding TMDL syntax rules (indentation, quoting, property ordering)33- Writing multi-line DAX in TMDL format34- Understanding the difference between `///` descriptions and `//` comments3536## Critical3738- **`///` (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.39- **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.40- **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.41- **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.4243## TMDL File Types4445| File | Contents | Location |46|------|----------|----------|47| `model.tmdl` | Model configuration, `ref table` entries, query groups, annotations | `definition/` |48| `database.tmdl` | Compatibility level, model ID | `definition/` |49| `relationships.tmdl` | All relationships between tables | `definition/` |50| `expressions.tmdl` | Shared M expressions and parameters | `definition/` |51| `functions.tmdl` | DAX user-defined functions (reusable parameterized DAX) | `definition/` |52| `roles/<RoleName>.tmdl` | One file per security role (RLS filters, role members, OLS) | `definition/roles/` |53| `perspectives/<Name>.tmdl` | One file per perspective (object membership) | `definition/perspectives/` |54| `dataSources.tmdl` | Legacy data source definitions (if present) | `definition/` |55| `tables/<Name>.tmdl` | Table definition with columns, measures, hierarchies, partitions | `definition/tables/` |56| `cultures/<locale>.tmdl` | Linguistic metadata and translations | `definition/cultures/` |5758## Object Nesting Rules5960Objects must be nested inside their correct parent. The validator enforces these rules:6162| Object | Allowed Parent(s) |63|--------|-------------------|64| `column`, `measure`, `hierarchy`, `partition`, `calculationGroup` | `table` |65| `level` | `hierarchy` |66| `calculationItem` | `calculationGroup` |67| `tablePermission` | `role` |68| `columnPermission` | `tablePermission` |69| `perspectiveTable` | `perspective` |70| `perspectiveColumn`, `perspectiveMeasure`, `perspectiveHierarchy` | `perspectiveTable` |71| `linguisticMetadata`, `translation` | `cultureInfo` |72| `dataAccessOptions` | `model` |73| `formatStringDefinition` | `measure`, `calculationItem` |74| `detailRowsDefinition` | `measure`, `table` |75| `alternateOf` | `column` |76| `member` | `role` |77| `annotation`, `extendedProperty` | any object (including `queryGroup`, `function`, `member`) |78| `ref` | `model`, `table` |7980Root-level objects (indent 0 only): `model`, `database`, `table`, `relationship`, `role`, `cultureInfo`, `perspective`, `dataSource`, `expression`, `queryGroup`, `function`.8182## Syntax Rules8384### Indentation8586TMDL 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:8788```tmdl89table Product // depth 0: top-level declaration90 lineageTag: abc-123 // depth 1: table property9192 measure '# Products' = // depth 1: measure declaration93 COUNTROWS ( // depth 3: DAX expression body (one deeper than properties)94 VALUES ( Product[Name] ) // depth 3: continued95 ) // depth 3: continued96 formatString: #,##0 // depth 2: measure property97 displayFolder: Measures // depth 2: measure property98 lineageTag: def-456 // depth 2: measure property99100 column 'Product Name' // depth 1: column declaration101 dataType: string // depth 2: column property102 lineageTag: ghi-789 // depth 2: column property103 summarizeBy: none // depth 2: column property104 sourceColumn: Product Name // depth 2: column property105106 annotation SummarizationSetBy = Automatic // depth 2: column annotation107```108109**Key rules:**110- Use tabs in PBIP files (Power BI Desktop's default); see the Critical section above for the spaces alternative111- Table-level objects (columns, measures, hierarchies, partitions) are at depth 1112- Properties of those objects are at depth 2113- 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)114- Annotations are at the same depth as properties of their parent object, separated by a blank line115116### Descriptions (`///`)117118Triple-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.119120```tmdl121/// Count of distinct products in the current filter context.122measure '# Products' =123 COUNTROWS ( VALUES ( Product[Product Name] ) )124 formatString: #,##0125 lineageTag: abc-123126```127128**Rules:**129- `///` must be immediately followed by a declaration on the next line130- No blank line between `///` and the declaration131- Multiple `///` lines concatenate into a single description132- `///` applies to the next `measure`, `column`, `table`, `hierarchy`, or `level`133134**Common mistake:**135```tmdl136// WRONG: blank line between /// and declaration137/// This is a description.138139measure 'My Measure' = 1140141// WRONG: /// used as a separator comment142///143measure 'My Measure' = 1144145// RIGHT: /// immediately before declaration146/// This is a description.147measure 'My Measure' = 1148149// RIGHT: // used for regular comments150// This is just a comment, not a description.151measure 'My Measure' = 1152```153154### Comments (`//`)155156Double-slash is a regular comment with no semantic effect:157158```tmdl159// This is a comment — it does not set any property160measure 'My Measure' = 1161```162163### Property Ordering164165Properties should follow a consistent order, though TMDL is not strict about it. The conventional order is:166167**For columns:** `dataType`, `isHidden`, `isKey`, `displayFolder`, `lineageTag`, `summarizeBy`, `isNameInferred`, `sourceColumn`, `sortByColumn`, then annotations.168169**For measures:** DAX expression (on the `=` line or multi-line), `formatString` or `formatStringDefinition`, `displayFolder`, `lineageTag`, then annotations.170171## Name Quoting172173### When to Quote174175Use single quotes around names that contain any of these characters:176- Spaces: `'Product Name'`177- Dots: `'Sales.Amount'`178- Equals: `'Price = Target'`179- Colons: `'Date:Key'`180- Single quotes (escape by doubling): `'Customer''s Name'`181- Other special characters: `'Sales ($)'`, `'OTD % (Value)'`, `'1) Selected Metric'`182- Names starting with a digit: `'4) Selected Period'`183184### When NOT to Quote185186Do not quote names that are simple identifiers:187- `Product` (simple word)188- `_Measures` (underscore prefix, no spaces)189- `Date` (simple word)190- `CgMetricQuantity` (PascalCase, no spaces)191192### Examples193194```tmdl195table Product // unquoted: simple name196table _Measures // unquoted: underscore prefix197table 'Budget Rate' // quoted: contains space198table 'Invoice Document Type' // quoted: contains spaces199table '1) Selected Metric' // quoted: starts with digit200table 'On-Time Delivery' // quoted: contains space201```202203## Column Definitions204205For complete column examples (basic, hidden, key, sortByColumn, description), see **`references/tmdl-file-examples.md`**. For full property reference, see **`references/column-properties.md`**.206207Key column pattern:208209```tmdl210column 'Product Name'211 dataType: string212 displayFolder: 1. Product Hierarchy213 lineageTag: abc-123214 summarizeBy: none215 sourceColumn: Product Name216217 annotation SummarizationSetBy = Automatic218```219220## Measure Definitions221222### Single-Line DAX223224```tmdl225measure '# Products' = COUNTROWS ( VALUES ( Product[Product Name] ) )226 formatString: #,##0227 displayFolder: Measures228 lineageTag: abc-123229```230231### Multi-Line DAX232233Two syntaxes for multi-line DAX:234235**1. Indented block** (most common) -- expression body indented two levels deeper than the declaration:236237**2. Triple-backtick block** -- DAX enclosed in `` ``` `` fences, useful for expressions with complex indentation:238239```tmdl240measure Percentage = ```241 VAR _Total = CALCULATE( SUM ( 'Table'[Quantitative] ), REMOVEFILTERS ( ) )242 RETURN243 DIVIDE ( SUM ( 'Table'[Quantitative] ), _Total )244 ```245 formatString: 0.0%;-0.0%;0.0%246 lineageTag: abc-123247```248249**Indented block syntax** (standard approach) -- indented two extra tabs from the measure's parent (table) level:250251```tmdl252measure 'Actuals MTD' =253 CALCULATE (254 [Actuals],255 CALCULATETABLE (256 DATESMTD ( 'Date'[Date] ),257 'Date'[IsDateInScope]258 )259 )260 formatString: #,##0261 displayFolder: 2. MTD\Actuals262 lineageTag: abc-123263```264265### Measure with Description266267```tmdl268/// Number of workdays elapsed month-to-date, considering only dates in scope.269measure '# Workdays MTD' =270 CALCULATE(271 MAX( 'Date'[Workdays MTD] ),272 'Date'[IsDateInScope] = TRUE273 )274 formatString: #,##0275 displayFolder: 5. Weekday / Workday\Measures\# Workdays276 lineageTag: abc-123277```278279### Measure with formatStringDefinition (Dynamic Format)280281```tmdl282measure 'Sales Target MTD vs. Actuals (%)' =283 Comparison.RelativeToTarget (284 [Actuals MTD],285 [Sales Target MTD]286 )287 displayFolder: 2. MTD\Sales Target288 lineageTag: abc-123289290 formatStringDefinition =291 FormatString.Comparison.RelativeToTarget (292 "SUFFIX",293 1,294 "ARROWS",295 "",296 ""297 )298```299300**Note:** `formatStringDefinition` replaces `formatString` when the format is computed dynamically via a DAX expression (often a calculation group format function).301302## Other Object Types303304For 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`**.305306307## Common Data Quality Patterns308309### summarizeBy Rules310311| Column Type | Correct `summarizeBy` | Reason |312|-------------|----------------------|--------|313| Keys (surrogate/natural) | `none` | Keys are never aggregated |314| Attributes (names, codes, types) | `none` | Text attributes are never summed |315| Dates | `none` | Dates are never summed |316| Boolean flags | `none` | Flags are never summed |317| Additive numeric facts (amounts, quantities) | `sum` | Default aggregation is SUM |318| Non-additive numeric facts (rates, percentages) | `none` | Cannot be meaningfully summed |319320**Common fix pattern** — changing `summarizeBy: sum` to `summarizeBy: none` for key columns:321322```tmdl323// Before (wrong - key column should not sum)324column 'Customer Key'325 dataType: int64326 isHidden327 lineageTag: abc-123328 summarizeBy: sum329 sourceColumn: Customer Key330331// After (correct)332column 'Customer Key'333 dataType: int64334 isHidden335 lineageTag: abc-123336 summarizeBy: none337 sourceColumn: Customer Key338```339340### formatString Patterns341342| Data Type | Pattern | Example |343|-----------|---------|---------|344| Integer | `#,##0` | 1,234 |345| Decimal (2 places) | `#,##0.00` | 1,234.56 |346| Percentage | `#,##0%` or `0.00%` | 85% or 85.00% |347| Currency | `$#,##0.00` | $1,234.56 |348| Date | `mm/dd/yyyy` or `dd/mm/yyyy` | 01/15/2024 |349350### PBI_FormatHint Annotation351352Power BI Desktop may add a `PBI_FormatHint` annotation alongside `formatString`:353354```tmdl355column Amount356 dataType: decimal357 formatString: #,##0.00358 lineageTag: abc-123359 summarizeBy: sum360 sourceColumn: Amount361362 annotation SummarizationSetBy = Automatic363364 annotation PBI_FormatHint = {"isGeneralNumber":true}365```366367**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.368369370## Quick Reference371372### Property Cheat Sheet373374For the complete property reference for every object type, see **`references/object-properties.md`**.375376| Object | Property | Values | Notes |377|--------|----------|--------|-------|378| Column | `dataType` | `string`, `int64`, `double`, `decimal`, `dateTime`, `boolean`, `binary`, `unknown`, `variant`, `automatic` | Required for data columns |379| Column | `summarizeBy` | `default`, `none`, `sum`, `min`, `max`, `count`, `average`, `distinctCount` | Use `none` for keys/attributes |380| Column | `type` | `data`, `calculated`, `rowNumber`, `calculatedTableColumn` | Column type variant |381| Column | `isHidden` | (flag, no value) | Boolean flags: write the keyword alone on its own line |382| Column | `isKey` | (flag, no value) | Marks the column as the table's key |383| Column | `isNullable` | (flag, no value) | Column allows nulls |384| Column | `isUnique` | (flag, no value) | Column values are unique |385| Column | `isNameInferred` | (flag, no value) | Name inferred from source |386| Column | `isDefaultLabel` | (flag, no value) | Default label for the table |387| Column | `isDefaultImage` | (flag, no value) | Default image for the table |388| Column | `isDataTypeInferred` | (flag, no value) | Data type inferred from source |389| Column | `isAvailableInMdx` | (flag, no value) | Available in MDX queries |390| Column | `keepUniqueRows` | (flag, no value) | Keep unique rows |391| Column | `encodingHint` | `default`, `hash`, `value` | Storage encoding hint |392| Column | `alignment` | `default`, `left`, `right`, `center` | Column alignment |393| Column | `displayFolder` | folder path string | Use `\` for nesting: `1. Year\Quarter` |394| Column | `sourceColumn` | source column name | Must match the Power Query output column |395| Column | `sortByColumn` | column name reference | Column to sort by (e.g., month name sorted by month number) |396| Column | `expression` | DAX expression | For calculated columns |397| Measure | `formatString` | format pattern | e.g., `#,##0`, `0.00%` |398| Measure | `displayFolder` | folder path string | Use `\` for nesting |399| Measure | `formatStringDefinition` | DAX expression block | Dynamic format string (replaces `formatString`) |400| Measure | `isHidden` | (flag, no value) | Hide the measure |401| Measure | `isSimpleMeasure` | (flag, no value) | Simple implicit-style measure |402| Measure | `dataCategory` | string | Semantic data category |403| Partition | `mode` | `import`, `directQuery`, `default`, `push`, `dual`, `directLake` | Storage mode |404| Partition | `sourceType` | `query`, `calculated`, `none`, `m`, `entity`, `policyRange`, `calculationGroup`, `inferred` | Source type |405| Relationship | `crossFilteringBehavior` | `oneDirection`, `bothDirections`, `automatic` | Cross-filter direction |406| Relationship | `securityFilteringBehavior` | `oneDirection`, `bothDirections`, `none` | RLS filter direction |407| Relationship | `fromCardinality` / `toCardinality` | `none`, `one`, `many` | Cardinality ends |408| Relationship | `isActive` | (flag, no value) | Active relationship |409| Role | `modelPermission` | `none`, `read`, `readRefresh`, `refresh`, `administrator` | Role permission level |410| Model | `discourageImplicitMeasures` | (flag, no value) | Disables implicit measures |411| Model | `defaultPowerBIDataSourceVersion` | `powerBI_V1`, `powerBI_V2`, `powerBI_V3` | PBI data source version |412| Model | `directLakeBehavior` | `automatic`, `directLakeOnly`, `directQueryOnly` | Direct Lake mode |413| All | `lineageTag` | GUID | Unique identifier, do not change existing values |414415### Indentation Depth Summary416417**Rule: a multi-line DAX body is always 2 levels deeper than its enclosing object declaration.**418419| Context | Depth | Tabs |420|---------|-------|------|421| Top-level declaration (`table`, `relationship`, `expression`) | 0 | 0 |422| Table properties, column/measure/hierarchy declarations | 1 | 1 |423| Column/measure properties, hierarchy levels | 2 | 2 |424| DAX body for measure/column declared at depth 1 (inside table) | 3 | 3 |425| Level properties | 3 | 3 |426| DAX body for top-level `function` declared at depth 0 | 2 | 2 |427| `calculationItem` inside `calculationGroup` (depth 1) | 2 | 2 |428| DAX body for `calculationItem` at depth 2 | 4 | 4 |429430## Additional Resources431432### Reference Files433434- **`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.)435- **`references/column-properties.md`** - Column-specific property guide with `summarizeBy` rules, `formatString` patterns, `PBI_FormatHint` behavior436- **`references/naming-conventions.md`** - SQLBI naming conventions, display folder conventions, measure table conventions, and calculation group naming437- **`references/bim-to-tmdl.md`** - Converting between `model.bim` (TMSL) and `definition/` (TMDL) via Tabular Editor CLI or TOM TmdlSerializer438- **`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 tables439440### Fetching Docs441442To 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.443444### Example Model445446- **`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:447 - `definition/functions.tmdl` -- DAX user-defined functions with parameters, types, and multi-line expressions448 - `definition/tables/Z04CG1 - Time Intelligence.tmdl` -- Calculation group with triple-backtick DAX449 - `definition/tables/__Measures.tmdl` -- Measures table with calculation group references450 - `definition/tables/Invoices.tmdl` -- Large fact table (51 measures, 18 columns)451 - `definition/tables/Date.tmdl` -- Calculated date table with 42 columns452 - `definition/roles/Account Managers.tmdl` -- RLS role with DAX filter expression453 - `definition/relationships.tmdl` -- 27 relationships including inactive454 - `definition/expressions.tmdl` -- Shared M/Power Query expressions and parameters455 - `definition/perspectives/Measure Selection.tmdl` -- Perspective definition456457### External References458459- [TMDL overview (Microsoft Learn)](https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-overview)460- [TMDL syntax reference (Microsoft Learn)](https://learn.microsoft.com/en-us/analysis-services/tmdl/tmdl-how-to)461- [SQLBI naming conventions](https://www.sqlbi.com/articles/rules-of-the-game-how-to-name-things-in-your-data-model/)462463---464465**Source:** [`data-goblin/power-bi-agentic-development`](https://github.com/data-goblin/power-bi-agentic-development) → `plugins/pbip/skills/tmdl/SKILL.md`