Rules / Formatting

Month (as a string) must be sorted

warning MONTH_(AS_A_STRING)_MUST_BE_SORTED · ported · model layer · scope: Column, CalculatedColumn, CalculatedTableColumn

What it checks

Text columns with month in the name, but not months, that have no sort-by column.

Each finding names the column, as 'Date'[Month Name].

Example

Fires the rule
table Date
	column 'Month Name'
		dataType: string
		summarizeBy: none
		sourceColumn: Month Name

	column 'Month Number'
		dataType: int64
		isHidden
		summarizeBy: none
		sourceColumn: Month Number
After the fix
table Date
	column 'Month Name'
		dataType: string
		summarizeBy: none
		sortByColumn: 'Month Number'
		sourceColumn: Month Name

	column 'Month Number'
		dataType: int64
		isHidden
		summarizeBy: none
		sourceColumn: Month Number

Why it matters

A text month sorts alphabetically: April, August, December. Every axis and slicer that uses the column shows that order until someone notices, and the fix has to be repeated in each visual unless it is made once on the column.

How to fix it

Add a month number column to the table, hide it, then in Power BI Desktop select the month name column and pick the number under Sort by column in Column tools. In the TMDL file the property is sortByColumn: 'Month Number' under the month name column. Each month name has to map to exactly one number, so a name like January that appears in several years needs a number column at the same grain, 1 through 12, not a year-month key; Power BI rejects the sort otherwise. Where the axis runs across years, sort a Month Year column by a year-month number instead and leave the plain month name for the within-year views.

When to ignore it

A text column the name test catches that is not a list of month names is noise: a Monthly Target note, a Month Comment, anything where alphabetical order is as good as any other. A month column whose values already sort correctly is the other case, such as one holding 2026-01 and 2026-02, where a sort-by column would only add a second column to maintain. Where the values are month names, there is no reason to leave the sort alphabetical.

To ignore this rule on one object, add annotation pbiplint.ignore = MONTH_(AS_A_STRING)_MUST_BE_SORTED under the object in its TMDL file. Power BI Desktop keeps the annotation. To turn the rule off for a whole project, set "MONTH_(AS_A_STRING)_MUST_BE_SORTED": "off" under rules in pbiplint.config.json.

Quirks

Ported from Microsoft's Best Practice Analyzer ruleset (opens in a new tab).

Check a model for this Improve this page (opens in a new tab)