Skip to content

Commit

Permalink
update_m_partition to use TOM object instead of 'set'
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Jun 24, 2024
1 parent 3a0cd25 commit 6c76ccb
Showing 1 changed file with 1 addition and 65 deletions.
66 changes: 1 addition & 65 deletions src/sempy_labs/tom/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3601,7 +3601,7 @@ def update_m_partition(self, table_name: str, partition_name: str, expression: O
import System

p = self.model.Tables[table_name].Partitions[partition_name]
if str(p.SourceType) != 'M':
if p.SourceType != TOM.PartitionSourceType.M:
raise ValueError(f"Invalid partition source type. This function is only for M partitions.")
if expression is not None:
p.Source.Expression = expression
Expand Down Expand Up @@ -3649,70 +3649,6 @@ def remove_sort_by_column(self, table_name: str, column_name: str):

self.model.Tables[table_name].Columns[column_name].SortByColumn = None

#def format_dax(self, measure_name: Optional[str | List[str] | None] = None, format_type: Optional[str] = 'short', format_region: Optional[str] = 'US'):

# """
# Formats the DAX expression of a measure in a semantic model.

# Parameters
# ----------
# measure_name : str, List[str], None, default=None
# Name of the measure.
# Defaults to None which formats all the measures in the semantic model.
# format_type : str, default='short'
# `Formatting type <https://www.sqlbi.com/blog/marco/2014/02/24/how-to-pass-a-dax-query-to-dax-formatter/>`_ in which the expression will be formatted.
# format_region : str, default='US'
# `Region <https://www.sqlbi.com/blog/marco/2014/02/24/how-to-pass-a-dax-query-to-dax-formatter/>`_ to use for formatting.
# """

# import requests
# from bs4 import BeautifulSoup

# def fmt(dax, format_type, format_region):

# url = "https://www.daxformatter.com"

# payload = {
# 'r': format_region,
# 'fx': dax,
# 'embed': '1',
# 's': 'auto',
# 'l': format_type
# }

# try:
# response = requests.post(url, data=payload)
# response.raise_for_status()

# soup = BeautifulSoup(response.text, 'html.parser')
# formatted_dax_div = soup.find('div', {'class': 'formatted'})

# for br in formatted_dax_div.find_all("br"):
# br.replace_with("\n")

# formatted_dax = formatted_dax_div.get_text(' ').replace('\xa0', ' ')
# return formatted_dax
# except Exception as e:
# raise ValueError(f"{icons.red_dot} The DAX expression could not be formatted.")

# if measure_name is None:
# for m in self.all_measures():
# expr = fmt(dax=m.Expression, format_type=format_type, format_region=format_region)
# if expr is not None:
# m.Expression = expr
# elif isinstance(measure_name, str):
# measure_name = [measure_name]
# if measure_name is not None:
# for ms in measure_name:
# try:
# meas = next(m for m in self.all_measures() if m.Name == ms)
# except Exception:
# raise ValueError(f"{icons.red_dot} The '{ms}' measure does not exist in the semantic model.")

# expr = fmt(measure_expression=meas.Expression, format_type=format_type, format_region=format_region)
# if expr is not None:
# meas.Expression = expr

def close(self):
if not self._readonly and self.model is not None:
self.model.SaveChanges()
Expand Down

0 comments on commit 6c76ccb

Please sign in to comment.