@@ -308,9 +308,10 @@ def remove(self, file_path: str, json_path: Optional[str] = None, verbose=True):
308308
309309 if not json_path :
310310 self ._report_definition ["parts" ].remove (part )
311- print (
312- f"{ icons .green_dot } The file '{ path } ' has been removed from the report definition."
313- )
311+ if verbose :
312+ print (
313+ f"{ icons .green_dot } The file '{ path } ' has been removed from the report definition."
314+ )
314315 else :
315316 remove_json_value (
316317 path = path , payload = payload , json_path = json_path , verbose = verbose
@@ -2125,13 +2126,14 @@ def migrate_report_level_measures(self, measures: Optional[str | List[str]] = No
21252126 if isinstance (measures , str ):
21262127 measures = [measures ]
21272128
2128- file = self .get (file_path = self . _report_extensions_path )
2129-
2130- mCount = 0
2129+ entities = self .get (
2130+ file_path = self . _report_extensions_path , json_path = "$.entities"
2131+ )
21312132 with connect_semantic_model (
2132- dataset = dataset_id , readonly = False , workspace = dataset_workspace_id
2133+ dataset = dataset_id , readonly = self . _readonly , workspace = dataset_workspace_id
21332134 ) as tom :
21342135 existing_measures = [m .Name for m in tom .all_measures ()]
2136+ # Add measure to semantic model
21352137 for _ , r in rlm .iterrows ():
21362138 table_name = r ["Table Name" ]
21372139 measure_name = r ["Measure Name" ]
@@ -2153,20 +2155,25 @@ def migrate_report_level_measures(self, measures: Optional[str | List[str]] = No
21532155 name = "semanticlinklabs" ,
21542156 value = "reportlevelmeasure" ,
21552157 )
2156- mCount += 1
2157- # Remove measures from the json
2158- if measures is not None and len (measures ) < mCount :
2159- for e in file ["entities" ]:
2160- e ["measures" ] = [
2161- measure
2162- for measure in e ["measures" ]
2163- if measure ["name" ] not in measures
2164- ]
2165- file ["entities" ] = [
2166- entity for entity in file ["entities" ] if entity ["measures" ]
2167- ]
2168- self .update (file_path = self ._report_extensions_path , payload = file )
2169- # what about if measures is None?
2158+
2159+ for entity in entities :
2160+ if entity .get ("name" ) == table_name :
2161+ entity ["measures" ] = [
2162+ m
2163+ for m in entity .get ("measures" , [])
2164+ if m .get ("name" ) != measure_name
2165+ ]
2166+ entities = [e for e in entities if e .get ("measures" )]
2167+ self .set_json (
2168+ file_path = self ._report_extensions_path ,
2169+ json_path = "$.entities" ,
2170+ json_value = entities ,
2171+ )
2172+ if not entities :
2173+ self .remove (
2174+ file_path = self ._report_extensions_path ,
2175+ verbose = False ,
2176+ )
21702177
21712178 if not self ._readonly :
21722179 print (
0 commit comments