sempy_labs.dax package

Module contents

sempy_labs.dax.format_dax(dax_expression: str, display: bool = True)

Color-codes a DAX expression for display in a notebook.

Uses the DAX parser/tokenizer to classify tokens and renders them with a soft, Apple-inspired palette that reads well on both light and dark backgrounds:

  • Functions and keywords - soft blue

  • VAR-declared variables - soft teal

  • Numeric literals - soft orange

  • Virtual columns (introduced by ADDCOLUMNS / SELECTCOLUMNS) - soft pink

Parameters:
  • dax_expression (str) – The DAX expression to color-code.

  • display (bool, default=True) – If True, displays the formatted DAX in the current notebook and returns None. If False, returns an IPython.display.HTML object instead.

Returns:

The HTML object when display=False; otherwise None.

Return type:

IPython.display.HTML | None

sempy_labs.dax.parse_dax(text: str, tom=None)

Parse a DAX expression and return its AST.

Parameters:
  • text (str) – The DAX expression.

  • tom (TOMWrapper | Microsoft.AnalysisServices.Tabular.Model, optional) – When supplied, the parser uses the model to disambiguate bare bracketed references. A [Name] reference resolves to a Measure node if a measure with that name exists, otherwise to a Column node with table=None (an unqualified column) if a column with that name exists, otherwise it falls back to Measure (the default when no model is provided).