sempy_labs.tom package

Module contents

class sempy_labs.tom.TOMWrapper(dataset, workspace, readonly)

Bases: object

Convenience wrapper around the TOM object model for a semantic model. Always use the connect_semantic_model function to make sure the TOM object is initialized correctly.

XMLA read/write endpoints must

be enabled if setting the readonly parameter to False.

add_calculated_column(table_name: str, column_name: str, expression: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a calculated column to a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table in which the column will be created.

  • column_name (str) – Name of the column.

  • expression (str) – The DAX expression for the column.

  • data_type (str) – The data type of the column.

  • format_string (str, default=None) – Format string of the column.

  • hidden (bool, default=False) – Whether the column will be hidden or visible.

  • description (str, default=None) – A description of the column.

  • display_folder (str, default=None) – The display folder in which the column will reside.

  • data_category (str, default=None) – The data category of the column.

  • key (bool, default=False) – Marks the column as the primary key of the table.

  • summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None which resolves to ‘Default’.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_calculated_table(name: str, expression: str, description: str | None = None, data_category: str | None = None, hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a calculated table to the semantic model.

Parameters:
  • name (str) – Name of the table.

  • expression (str) – The DAX expression for the calculated table.

  • description (str, default=None) – A description of the table.

  • data_catgegory (str, default=None) – The data category for the table.

  • hidden (bool, default=False) – Whether the table is hidden or visible.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_calculated_table_column(table_name: str, column_name: str, source_column: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a calculated table column to a calculated table within a semantic model.

Parameters:
  • table_name (str) – Name of the table in which the column will be created.

  • column_name (str) – Name of the column.

  • source_column (str) – The source column for the column.

  • data_type (str) – The data type of the column.

  • format_string (str, default=None) – Format string of the column.

  • hidden (bool, default=False) – Whether the column will be hidden or visible.

  • description (str, default=None) – A description of the column.

  • display_folder (str, default=None) – The display folder in which the column will reside.

  • data_category (str, default=None) – The data category of the column.

  • key (bool, default=False) – Marks the column as the primary key of the table.

  • summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None resolves to ‘Default’.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_calculation_group(name: str, precedence: int, description: str | None = None, hidden: bool = False)

Adds a calculation group to a semantic model.

Parameters:
  • name (str) – Name of the calculation group.

  • precedence (int) – The precedence of the calculation group.

  • description (str, default=None) – A description of the calculation group.

  • hidden (bool, default=False) – Whether the calculation group is hidden/visible.

add_calculation_item(table_name: str, calculation_item_name: str, expression: str, ordinal: int | None = None, description: str | None = None, format_string_expression: str | None = None)
Adds a calculation item to

a calculation group within a semantic model.

Parameters:
  • table_name (str) – Name of the table in which the calculation item will be created.

  • calculation_item_name (str) – Name of the calculation item.

  • expression (str) – The DAX expression for the calculation item.

  • ordinal (int, default=None) – The ordinal of the calculation item.

  • format_string_expression (str, default=None) – The format string expression for the calculation item.

  • description (str, default=None) – A description of the calculation item.

add_changed_property(object, property: str)

Adds a ChangedProperty property to a semantic model object. Only adds the property if it does not already exist for the object.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • property (str) – The property to set (i.e. ‘Name’, ‘DataType’).

add_data_column(table_name: str, column_name: str, source_column: str, data_type: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool = False, summarize_by: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a data column to a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table in which the column will be created.

  • column_name (str) – Name of the column.

  • source_column (str) – The source column for the column.

  • data_type (str) – The data type of the column.

  • format_string (str, default=None) – Format string of the column.

  • hidden (bool, default=False) – Whether the column will be hidden or visible.

  • description (str, default=None) – A description of the column.

  • display_folder (str, default=None) – The display folder in which the column will reside.

  • data_category (str, default=None) – The data category of the column.

  • key (bool, default=False) – Marks the column as the primary key of the table.

  • summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None resolves to ‘Default’.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_entity_partition(table_name: str, entity_name: str, expression: str | None = None, description: str | None = None, schema_name: str = 'dbo')

Adds an entity partition to a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • entity_name (str) – Name of the lakehouse/warehouse table.

  • expression (TOM Object, default=None) – The expression used by the table. Defaults to None which resolves to the ‘DatabaseQuery’ expression.

  • description (str, default=None) – A description for the partition.

  • schema_name (str, default="dbo") – The schema name.

add_expression(name: str, expression: str, description: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds an expression to a semantic model.

Parameters:
  • name (str) – Name of the expression.

  • expression (str) – The M expression of the expression.

  • description (str, default=None) – A description of the expression.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_field_parameter(table_name: str, objects: List[str], object_names: List[str] = None)

Adds a field parameter to the semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • objects (List[str]) – The columns/measures to be included in the field parameter. Columns must be specified as such : ‘Table Name’[Column Name]. Measures may be formatted as ‘[Measure Name]’ or ‘Measure Name’.

  • object_names (List[str], default=None) – The corresponding visible name for the measures/columns in the objects list. Defaults to None which shows the measure/column name.

add_hierarchy(table_name: str, hierarchy_name: str, columns: List[str], levels: List[str] | None = None, hierarchy_description: str | None = None, hierarchy_hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a hierarchy to a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • hierarchy_name (str) – Name of the hierarchy.

  • columns (List[str]) – Names of the columns to use within the hierarchy.

  • levels (List[str], default=None) – Names of the levels to use within the hierarhcy (instead of the column names).

  • hierarchy_description (str, default=None) – A description of the hierarchy.

  • hierarchy_hidden (bool, default=False) – Whether the hierarchy is visible or hidden.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_incremental_refresh_policy(table_name: str, column_name: str, start_date: str, end_date: str, incremental_granularity: str, incremental_periods: int, rolling_window_granularity: str, rolling_window_periods: int, only_refresh_complete_days: bool = False, detect_data_changes_column: str | None = None)

Adds an incremental refresh policy for a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – The DateTime column to be used for the RangeStart and RangeEnd parameters.

  • start_date (str) – The date to be used for the RangeStart parameter.

  • end_date (str) – The date to be used for the RangeEnd parameter.

  • incremental_granularity (str) – Granularity of the (most recent) incremental refresh range.

  • incremental_periods (int) – Number of periods for the incremental refresh range.

  • rolling_window_granularity (str) – Target granularity of the rolling window for the whole semantic model.

  • rolling_window_periods (int) – Number of periods for the rolling window for the whole semantic model.

  • only_refresh_complete_days (bool, default=False) – Lag or leading periods from Now() to the rolling window head.

  • detect_data_changes_column (str, default=None) – The column to use for detecting data changes. Defaults to None which resolves to not detecting data changes.

add_m_partition(table_name: str, partition_name: str, expression: str, mode: str | None = None, description: str | None = None)

Adds an M-partition to a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • partition_name (str) – Name of the partition.

  • expression (str) – The M expression encapsulating the logic for the partition.

  • mode (str, default=None) – The query mode for the partition. Defaults to None which resolves to ‘Import’. Valid mode values

  • description (str, default=None) – A description for the partition.

add_measure(table_name: str, measure_name: str, expression: str, format_string: str | None = None, hidden: bool = False, description: str | None = None, display_folder: str | None = None, format_string_expression: str | None = None, data_category: str | None = None, lineage_tag: str | None = None, source_lineage_tag: str | None = None, detail_rows_expression: str | None = None)

Adds a measure to the semantic model.

Parameters:
  • table_name (str) – Name of the table in which the measure will be created.

  • measure_name (str) – Name of the measure.

  • expression (str) – DAX expression of the measure.

  • format_string (str, default=None) – Format string of the measure.

  • hidden (bool, default=False) – Whether the measure will be hidden or visible.

  • description (str, default=None) – A description of the measure.

  • display_folder (str, default=None) – The display folder in which the measure will reside.

  • format_string_expression (str, default=None) – The format string expression.

  • data_category (str, default=None) – Specifies the type of data contained in the measure so that you can add custom behaviors based on measure type.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

  • detail_rows_expression (str, default=None) – The detail rows expression.

add_perspective(perspective_name: str)

Adds a perspective to a semantic model.

Parameters:

perspective_name (str) – Name of the perspective.

add_relationship(from_table: str, from_column: str, to_table: str, to_column: str, from_cardinality: str, to_cardinality: str, cross_filtering_behavior: str | None = None, is_active: bool = True, security_filtering_behavior: str | None = None, rely_on_referential_integrity: bool = False)

Adds a relationship to a semantic model.

Parameters:
  • from_table (str) – Name of the table on the ‘from’ side of the relationship.

  • from_column (str) – Name of the column on the ‘from’ side of the relationship.

  • to_table (str) – Name of the table on the ‘to’ side of the relationship.

  • to_column (str) – Name of the column on the ‘to’ side of the relationship.

  • from_cardinality (str) – The cardinality of the ‘from’ side of the relationship. Options: [‘Many’, ‘One’, ‘None’].

  • to_cardinality (str) – The cardinality of the ‘to’ side of the relationship. Options: [‘Many’, ‘One’, ‘None’].

  • cross_filtering_behavior (str, default=None) – Setting for the cross filtering behavior of the relationship. Options: (‘Automatic’, ‘OneDirection’, ‘BothDirections’). Defaults to None which resolves to ‘Automatic’.

  • is_active (bool, default=True) – Setting for whether the relationship is active or not.

  • security_filtering_behavior (str, default=None) – Setting for the security filtering behavior of the relationship. Options: (‘None’, ‘OneDirection’, ‘BothDirections’). Defaults to None which resolves to ‘OneDirection’.

  • rely_on_referential_integrity (bool, default=False) – Setting for the rely on referential integrity of the relationship.

add_role(role_name: str, model_permission: str | None = None, description: str | None = None)

Adds a role to a semantic model.

Parameters:
  • role_name (str) – Name of the role.

  • model_permission (str, default=None) – The model permission for the role. Defaults to None which resolves to ‘Read’.

  • description (str, default=None) – A description of the role.

add_table(name: str, description: str | None = None, data_category: str | None = None, hidden: bool = False, lineage_tag: str | None = None, source_lineage_tag: str | None = None)

Adds a table to the semantic model.

Parameters:
  • name (str) – Name of the table.

  • description (str, default=None) – A description of the table.

  • data_catgegory (str, default=None) – The data category for the table.

  • hidden (bool, default=False) – Whether the table is hidden or visible.

  • lineage_tag (str, default=None) – A tag that represents the lineage of the object.

  • source_lineage_tag (str, default=None) – A tag that represents the lineage of the source for the object.

add_time_intelligence(measure_name: str, date_table: str, time_intel: str | List[str])

Adds time intelligence measures

Parameters:
  • measure_name (str) – Name of the measure

  • date_table (str) – Name of the date table.

  • time_intel (str, List[str]) – Time intelligence measures to create (i.e. MTD, YTD, QTD).

add_to_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str)

Adds an object to a perspective.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • perspective_name (str) – Name of the perspective.

add_translation(language: str)

Adds a translation language (culture) to a semantic model.

Parameters:

language (str) – The language code (i.e. ‘it-IT’ for Italian).

all_calculated_columns()

Outputs a list of all calculated columns within all tables in the semantic model.

Returns:

All calculated columns within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Column]

all_calculated_tables()

Outputs a list of all calculated tables in the semantic model.

Returns:

All calculated tables within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Table]

all_calculation_groups()

Outputs a list of all calculation groups in the semantic model.

Returns:

All calculation groups within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Table]

all_calculation_items()

Outputs a list of all calculation items in the semantic model.

Returns:

All calculation items within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.CalculationItem]

all_columns()

Outputs a list of all columns within all tables in the semantic model.

Returns:

All columns within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Column]

all_date_tables()

Outputs the tables which are marked as date tables within a semantic model.

Returns:

All tables marked as date tables within a semantic model.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection

all_hierarchies()

Outputs a list of all hierarchies in the semantic model.

Returns:

All hierarchies within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Hierarchy]

all_hybrid_tables()

Outputs the hybrid tables within a semantic model.

Returns:

All hybrid tables within a semantic model.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection

all_levels()

Outputs a list of all levels in the semantic model.

Returns:

All levels within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Level]

all_measures()

Outputs a list of all measures in the semantic model.

Returns:

All measures within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Measure]

all_partitions()

Outputs a list of all partitions in the semantic model.

Returns:

All partitions within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.Partition]

all_rls()

Outputs a list of all row level security expressions in the semantic model.

Returns:

All row level security expressions within the semantic model.

Return type:

Iterator[Microsoft.AnalysisServices.Tabular.TablePermission]

apply_refresh_policy(table_name: str, effective_date: datetime | None = None, refresh: bool = True, max_parallelism: int | None = 0)

Applies the incremental refresh policy for a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • effective_date (DateTime, default=None) – The effective date that is used when calculating the partitioning scheme.

  • refresh (bool, default=True) – An indication if partitions of the table should be refreshed or not; the default behavior is to do the refresh.

  • max_parallelism (int, default=0) – The degree of parallelism during the refresh execution.

cardinality(column: TOM.Column)

Obtains the cardinality of a column within a semantic model.

Parameters:

column (TOM Object) – The column object within the semantic model.

Returns:

Cardinality of the TOM column.

Return type:

int

clear_annotations(object)

Removes all annotations on an object within the semantic model.

Parameters:

object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

clear_extended_properties(object)

Removes all extended properties on an object within the semantic model.

Parameters:

object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

close()
data_size(column: TOM.Column)

Obtains the data size of a column within a semantic model.

Parameters:

column (TOM Object) – The column object within the semantic model.

Returns:

Data size of the TOM column.

Return type:

int

depends_on(object, dependencies: DataFrame)

Obtains the objects on which the specified object depends.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Returns:

Objects on which the specified object depends.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection

dictionary_size(column: TOM.Column)

Obtains the dictionary size of a column within a semantic model.

Parameters:

column (TOM Object) – The column object within the semantic model.

Returns:

Dictionary size of the TOM column.

Return type:

int

fully_qualified_measures(object: TOM.Measure, dependencies: DataFrame)

Obtains all fully qualified measure references for a given object.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Returns:

All fully qualified measure references for a given object.

Return type:

Microsoft.AnalysisServices.Tabular.MeasureCollection

generate_measure_descriptions(measure_name: str | List[str] | None = None, max_batch_size: int | None = 5) DataFrame

Auto-generates descriptions for measures using an LLM. This function requires a paid F-sku (Fabric) of F64 or higher. Setting the ‘readonly’ parameter in connect_semantic_model to True will allow you to see the auto-generated descriptions in a dataframe. Setting the ‘readonly’ parameter to False will update the descriptions for the measures within the ‘measure_name’ parameter.

Parameters:
  • measure_name (str | List[str], default=None) – The measure name (or a list of measure names). Defaults to None which generates descriptions for all measures in the semantic model.

  • max_batch_size (int, default=5) – Sets the max batch size for each API call.

Returns:

A pandas dataframe showing the updated measure(s) and their new description(s).

Return type:

pandas.DataFrame

get_annotation_value(object, name: str)

Obtains the annotation value for a given annotation on an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • name (str) – Name of the annotation.

Returns:

The annotation value.

Return type:

str

get_annotations(object) Microsoft.AnalysisServices.Tabular.Annotation

Shows all annotations for a given object within a semantic model.

Parameters:

object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

Returns:

TOM objects of all the annotations on a particular object within the semantic model.

Return type:

Microsoft.AnalysisServices.Tabular.Annotation

get_extended_properties(object) Microsoft.AnalysisServices.Tabular.ExtendedProperty

Retrieves all extended properties on an object within the semantic model.

Parameters:

object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

Returns:

TOM Objects of all the extended properties.

Return type:

Microsoft.AnalysisServices.Tabular.ExtendedPropertiesCollection

get_extended_property_value(object, name: str)

Retrieves the value of an extended property for an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • name (str) – Name of the annotation.

Returns:

The extended property value.

Return type:

str

has_aggs()

Identifies if a semantic model has any aggregations.

Returns:

Indicates if the semantic model has any aggregations.

Return type:

bool

has_date_table()

Identifies if a semantic model has a table marked as a date table.

Returns:

Indicates if the semantic model has a table marked as a date table.

Return type:

bool

has_hybrid_table()

Identifies if a semantic model has a hybrid table.

Returns:

Indicates if the semantic model has a hybrid table.

Return type:

bool

has_incremental_refresh_policy(table_name: str)

Identifies whether a table has an incremental refresh policy.

Parameters:

table_name (str) – Name of the table.

Returns:

An indicator whether a table has an incremental refresh policy.

Return type:

bool

in_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str)

Indicates whether an object is contained within a given perspective.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • perspecitve_name (str) – Name of the perspective.

Returns:

An indication as to whether the object is contained within the given perspective.

Return type:

bool

is_agg_table(table_name: str)

Identifies if a table has aggregations.

Parameters:

table_name (str) – Name of the table.

Returns:

Indicates if the table has any aggregations.

Return type:

bool

is_auto_date_table(table_name: str)

Identifies if a table is an auto date/time table.

Parameters:

table_name (str) – Name of the table.

Returns:

Indicates if the table is an auto-date table.

Return type:

bool

is_calculated_column(table_name: str, column_name: str)

Identifies if a column is a calculated column.

Parameters:
  • table_name (str) – Name of the table in which the column resides.

  • column_name (str) – Name of the column.

Returns:

A boolean value indicating whether the column is a calculated column.

Return type:

bool

is_calculated_table(table_name: str)

Identifies if a table is a calculated table.

Parameters:

table_name (str) – Name of the table.

Returns:

A boolean value indicating whether the table is a calculated table.

Return type:

bool

is_date_table(table_name: str)

Identifies if a table is marked as a date tables.

Parameters:

table_name (str) – Name of the table.

Returns:

Indicates if the table is marked as a date table.

Return type:

bool

is_direct_lake()

Identifies if a semantic model is in Direct Lake mode.

Returns:

Indicates if the semantic model is in Direct Lake mode.

Return type:

bool

is_direct_lake_using_view()

Identifies whether a semantic model is in Direct lake mode and uses views from the lakehouse.

Returns:

An indicator whether a semantic model is in Direct lake mode and uses views from the lakehouse.

Return type:

bool

is_field_parameter(table_name: str)

Identifies if a table is a field parameter.

Parameters:

table_name (str) – Name of the table.

Returns:

Indicates if the table is a field parameter.

Return type:

bool

is_hybrid_table(table_name: str)

Identifies if a table is a hybrid table.

Parameters:

table_name (str) – Name of the table.

Returns:

Indicates if the table is a hybrid table.

Return type:

bool

mark_as_date_table(table_name: str, column_name: str)

Marks a table as a date table.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the date column in the table.

records_per_segment(object: TOM.Partition)

Obtains the records per segment of a partition within a semantic model.

Parameters:

object (TOM Object) – The partition object within the semantic model.

Returns:

Number of records per segment within the partition.

Return type:

float

referenced_by(object, dependencies: DataFrame)

Obtains the objects which reference the specified object.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Returns:

Objects which reference the specified object.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection

remove_alternate_of(table_name: str, column_name: str)

Removes the alternate of property on a column.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

remove_annotation(object, name: str)

Removes an annotation on an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • name (str) – Name of the annotation.

remove_changed_property(object, property: str)

Removes a ChangedProperty property to a semantic model object. Only adds the property if it does not already exist for the object.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • property (str) – The property to set (i.e. ‘Name’, ‘DataType’).

remove_extended_property(object, name: str)

Removes an extended property on an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • name (str) – Name of the annotation.

remove_from_perspective(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy, perspective_name: str)

Removes an object from a perspective.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • perspective_name (str) – Name of the perspective.

remove_object(object)

Removes an object from a semantic model.

Parameters:

object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

remove_sort_by_column(table_name: str, column_name: str)

Removes the sort by column for a column in a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

remove_translation(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy | TOM.Level, language: str)

Removes an object’s translation value.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • language (str) – The language code.

remove_vertipaq_annotations()

Removes the annotations set using the set_vertipaq_annotations function.

row_count(object: TOM.Partition | TOM.Table)

Obtains the row count of a table or partition within a semantic model.

Parameters:

object (TOM Object) – The table/partition object within the semantic model.

Returns:

Number of rows within the TOM object.

Return type:

int

set_aggregations(table_name: str, agg_table_name: str)

Sets the aggregations (alternate of) for all the columns in an aggregation table based on a base table.

Parameters:
  • table_name (str) – Name of the base table.

  • agg_table_name (str) – Name of the aggregation table.

set_alternate_of(table_name: str, column_name: str, summarization_type: str, base_table: str, base_column: str | None = None)

Sets the alternate of property on a column.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

  • summarization_type (str) – The summarization type for the column. Summarization valid values

  • base_table (str) – Name of the base table for aggregation.

  • base_column (str) – Name of the base column for aggregation

set_annotation(object, name: str, value: str)

Sets an annotation on an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • name (str) – Name of the annotation.

  • value (str) – Value of the annotation.

set_data_coverage_definition(table_name: str, partition_name: str, expression: str)

Sets the data coverage definition for a partition.

Parameters:
  • table_name (str) – Name of the table.

  • partition_name (str) – Name of the partition.

  • expression (str) – DAX expression containing the logic for the data coverage definition.

set_data_type(table_name: str, column_name: str, value: str)

Sets the data type for a column.

Parameters:
set_direct_lake_behavior(direct_lake_behavior: str)

Sets the Direct Lake Behavior property for a semantic model.

Parameters:

direct_lake_behavior (str) – The DirectLakeBehavior property value. DirectLakeBehavior valid values

set_encoding_hint(table_name: str, column_name: str, value: str)

Sets the encoding hint for a column.

Parameters:
set_extended_property(object, extended_property_type: str, name: str, value: str)

Sets an extended property on an object within the semantic model.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • extended_property_type (str) – The extended property type. Extended property valid values

  • name (str) – Name of the extended property.

  • value (str) – Value of the extended property.

set_is_available_in_mdx(table_name: str, column_name: str, value: bool = False)

Sets the IsAvailableInMDX property on a column.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

  • value (bool, default=False) – The IsAvailableInMdx property value.

set_kpi(measure_name: str, target: int | float | str, lower_bound: float, upper_bound: float, lower_mid_bound: float | None = None, upper_mid_bound: float | None = None, status_type: str | None = None, status_graphic: str | None = None)

Sets the properties to add/update a KPI for a measure.

Parameters:
  • measure_name (str) – Name of the measure.

  • target (str, int, float) – The target for the KPI. This can either be a number or the name of a different measure in the semantic model.

  • lower_bound (float) – The lower bound for the KPI.

  • upper_bound (float) – The upper bound for the KPI.

  • lower_mid_bound (float, default=None) – The lower-mid bound for the KPI. Set this if status_type is ‘Centered’ or ‘CenteredReversed’.

  • upper_mid_bound (float, default=None) – The upper-mid bound for the KPI. Set this if status_type is ‘Centered’ or ‘CenteredReversed’.

  • status_type (str, default=None) – The status type of the KPI. Options: ‘Linear’, ‘LinearReversed’, ‘Centered’, ‘CenteredReversed’. Defaults to None which resolvs to ‘Linear’.

  • status_graphic (str, default=None) – The status graphic for the KPI. Defaults to ‘Three Circles Colored’.

set_ols(role_name: str, table_name: str, column_name: str, permission: str)

Sets the object level security permissions for a column within a role.

Parameters:
  • role_name (str) – Name of the role.

  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

  • permission (str) – The object level security permission for the column. Permission valid values

set_rls(role_name: str, table_name: str, filter_expression: str)

Sets the row level security permissions for a table within a role.

Parameters:
  • role_name (str) – Name of the role.

  • table_name (str) – Name of the table.

  • filter_expression (str) – The DAX expression containing the row level security filter expression logic.

set_sort_by_column(table_name: str, column_name: str, sort_by_column: str)

Sets the sort by column for a column in a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

  • sort_by_column (str) – Name of the column to use for sorting. Must be of integer (Int64) data type.

set_summarize_by(table_name: str, column_name: str, value: str | None = None)

Sets the SummarizeBy property on a column.

Parameters:
  • table_name (str) – Name of the table.

  • column_name (str) – Name of the column.

  • value (bool, default=None) – The SummarizeBy property value. Defaults to none which resolves to ‘Default’. Aggregate valid values

set_translation(object: TOM.Table | TOM.Column | TOM.Measure | TOM.Hierarchy | TOM.Level, language: str, property: str, value: str)

Sets a translation value for an object’s property.

Parameters:
  • object (TOM Object) – An object (i.e. table/column/measure) within a semantic model.

  • language (str) – The language code.

  • property (str) – The property to set. Options: ‘Name’, ‘Description’, ‘Display Folder’.

  • value (str) – The transation value.

set_vertipaq_annotations()

Saves Vertipaq Analyzer statistics as annotations on objects in the semantic model.

show_incremental_refresh_policy(table_name: str)

Prints the incremental refresh policy for a table.

Parameters:

table_name (str) – Name of the table.

total_size(object: TOM.Table | TOM.Column)

Obtains the data size of a table/column within a semantic model.

Parameters:

object (TOM Object) – The table/column object within the semantic model.

Returns:

Total size of the TOM table/column.

Return type:

int

unqualified_columns(object: TOM.Column, dependencies: DataFrame)

Obtains all unqualified column references for a given object.

Parameters:
  • object (TOM Object) – The TOM object within the semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Returns:

All unqualified column references for a given object.

Return type:

Microsoft.AnalysisServices.Tabular.ColumnCollection

update_calculation_item(table_name: str, calculation_item_name: str, expression: str | None = None, ordinal: int | None = None, description: str | None = None, format_string_expression: str | None = None)

Updates a calculation item within a semantic model.

Parameters:
  • table_name (str) – Name of the calculation group (table).

  • calculation_item_name (str) – Name of the calculation item.

  • expression (str, default=None) – The DAX expression of the calculation item. Defaults to None which keeps the existing setting.

  • ordinal (int, default=None) – The ordinal of the calculation item. Defaults to None which keeps the existing setting.

  • description (str, default=None) – The description of the role. Defaults to None which keeps the existing setting.

  • format_string_expression (str, default=None) – The format string expression for the calculation item. Defaults to None which keeps the existing setting.

update_column(table_name: str, column_name: str, source_column: str | None = None, data_type: str | None = None, expression: str | None = None, format_string: str | None = None, hidden: bool | None = None, description: str | None = None, display_folder: str | None = None, data_category: str | None = None, key: bool | None = None, summarize_by: str | None = None, is_nullable: bool | None = None, is_available_in_mdx: bool | None = None)

Updates a column within a semantic model.

Parameters:
  • table_name (str) – Name of the table in which the column exists.

  • column_name (str) – Name of the column.

  • source_column (str, default=None) – The source column for the column (for data columns only). Defaults to None which keeps the existing setting.

  • data_type (str, default=None) – The data type of the column. Defaults to None which keeps the existing setting.

  • expression (str, default=None) – The DAX expression of the column (for calculated columns only). Defaults to None which keeps the existing setting.

  • format_string (str, default=None) – Format string of the column. Defaults to None which keeps the existing setting.

  • hidden (bool, default=None) – Whether the column will be hidden or visible. Defaults to None which keeps the existing setting.

  • description (str, default=None) – A description of the column. Defaults to None which keeps the existing setting.

  • display_folder (str, default=None) – The display folder in which the column will reside. Defaults to None which keeps the existing setting.

  • data_category (str, default=None) – The data category of the column. Defaults to None which keeps the existing setting.

  • key (bool, default=False) – Marks the column as the primary key of the table. Defaults to None which keeps the existing setting.

  • summarize_by (str, default=None) – Sets the value for the Summarize By property of the column. Defaults to None which keeps the existing setting.

  • is_nullable (bool, default=None) – If False, the column cannot contain nulls. Even if True, it may still not allow nulls if it’s a key column.

  • is_available_in_mdx (bool, default=None) – A boolean value that indicates whether the column can be excluded from usage in MDX query tools. False if the column can be excluded from usage in MDX query tools; otherwise true.

update_incremental_refresh_policy(table_name: str, incremental_granularity: str, incremental_periods: int, rolling_window_granularity: str, rolling_window_periods: int, only_refresh_complete_days: bool = False, detect_data_changes_column: str | None = None)

Updates the incremental refresh policy for a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • incremental_granularity (str) – Granularity of the (most recent) incremental refresh range.

  • incremental_periods (int) – Number of periods for the incremental refresh range.

  • rolling_window_granularity (str) – Target granularity of the rolling window for the whole semantic model.

  • rolling_window_periods (int) – Number of periods for the rolling window for the whole semantic model.

  • only_refresh_complete_days (bool, default=False) – Lag or leading periods from Now() to the rolling window head.

  • detect_data_changes_column (str, default=None) – The column to use for detecting data changes. Defaults to None which resolves to not detecting data changes.

update_lineage_tags()

Adds lineage and source lineage tags for relevant semantic model objects if they do not exist. Also updates schema name for Direct Lake (entity) partitions.

update_m_partition(table_name: str, partition_name: str, expression: str | None = None, mode: str | None = None, description: str | None = None)

Updates an M partition for a table within a semantic model.

Parameters:
  • table_name (str) – Name of the table.

  • partition_name (str) – Name of the partition.

  • expression (str, default=None) – The M expression containing the logic for the partition. Defaults to None which keeps the existing setting.

  • mode (str, default=None) – The query mode of the partition. Defaults to None which keeps the existing setting.

  • description (str, default=None) – The description of the partition. Defaults to None which keeps the existing setting.

update_measure(measure_name: str, expression: str | None = None, format_string: str | None = None, hidden: bool | None = None, description: str | None = None, display_folder: str | None = None, format_string_expression: str | None = None)

Updates a measure within a semantic model.

Parameters:
  • measure_name (str) – Name of the measure.

  • expression (str, default=None) – DAX expression of the measure. Defaults to None which keeps the existing setting.

  • format_string (str, default=None) – Format string of the measure. Defaults to None which keeps the existing setting.

  • hidden (bool, default=None) – Whether the measure will be hidden or visible. Defaults to None which keeps the existing setting.

  • description (str, default=None) – A description of the measure. Defaults to None which keeps the existing setting.

  • display_folder (str, default=None) – The display folder in which the measure will reside. Defaults to None which keeps the existing setting.

  • format_string_expression (str, default=None) – The format string expression for the calculation item. Defaults to None which keeps the existing setting.

update_role(role_name: str, model_permission: str | None = None, description: str | None = None)

Updates a role within a semantic model.

Parameters:
  • role_name (str) – Name of the role.

  • model_permission (str, default=None) – The model permission for the role. Defaults to None which keeps the existing setting.

  • description (str, default=None) – The description of the role. Defaults to None which keeps the existing setting.

used_in_calc_item(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)

Identifies the … which reference a given object.

Parameters:
  • object (TOM Object) – An object (i.e. table/column) within a semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection

used_in_data_coverage_definition(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)

Identifies the … which reference a given object.

Parameters:
  • object (TOM Object) – An object (i.e. table/column) within a semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection

used_in_hierarchies(column: TOM.Column)

Shows all hierarchies in which a column is used.

Parameters:

object (TOM Object) – An column object within a semantic model.

Returns:

All hierarchies in which the column is used.

Return type:

Microsoft.AnalysisServices.Tabular.HierarchyCollection

used_in_levels(column: TOM.Column)

Shows all levels in which a column is used.

Parameters:

object (TOM Object) – An column object within a semantic model.

Returns:

All levels in which the column is used.

Return type:

Microsoft.AnalysisServices.Tabular.LevelCollection

used_in_relationships(object: TOM.Table | TOM.Column)

Shows all relationships in which a table/column is used.

Parameters:

object (TOM Object) – An object (i.e. table/column) within a semantic model.

Returns:

All relationships in which the table/column is used.

Return type:

Microsoft.AnalysisServices.Tabular.RelationshipCollection

used_in_rls(object: TOM.Table | TOM.Column | TOM.Measure, dependencies: DataFrame)

Identifies the row level security filter expressions which reference a given object.

Parameters:
  • object (TOM Object) – An object (i.e. table/column) within a semantic model.

  • dependencies (pandas.DataFrame) – A pandas dataframe with the output of the ‘get_model_calc_dependencies’ function.

Return type:

Microsoft.AnalysisServices.Tabular.TableCollection, Microsoft.AnalysisServices.Tabular.ColumnCollection, Microsoft.AnalysisServices.Tabular.MeasureCollection

used_in_sort_by(column: TOM.Column)

Shows all columns in which a column is used for sorting.

Parameters:

object (TOM Object) – An column object within a semantic model.

Returns:

All columns in which the column is used for sorting.

Return type:

Microsoft.AnalysisServices.Tabular.ColumnCollection

used_size(object: TOM.Hierarchy | TOM.Relationship)

Obtains the used size of a hierarchy or relationship within a semantic model.

Parameters:

object (TOM Object) – The hierarhcy/relationship object within the semantic model.

Returns:

Used size of the TOM object.

Return type:

int

sempy_labs.tom.connect_semantic_model(dataset: str, readonly: bool = True, workspace: str | None = None) Iterator[TOMWrapper]

Connects to the Tabular Object Model (TOM) within a semantic model.

Parameters:
  • dataset (str) – Name of the semantic model.

  • readonly (bool, default=True) – Whether the connection is read-only or read/write. Setting this to False enables read/write which saves the changes made back to the server.

  • workspace (str, default=None) – The Fabric workspace name. Defaults to None which resolves to the workspace of the attached lakehouse or if no lakehouse attached, resolves to the workspace of the notebook.

Returns:

A connection to the semantic model’s Tabular Object Model.

Return type:

Iterator[TOMWrapper]