Forum Discussion
Error Data Warehouse/Lakehouse
- 1 year ago
Hi HarderT ,
You can utilise Semantic Link Labs to repoint to new lakehouse.
import sempy.fabric as fabricfrom sempy_labs.directlake._get_shared_expression import get_shared_expressionfrom sempy_labs._helper_functions import (resolve_lakehouse_name,)from sempy_labs.tom import connect_semantic_modelfrom typing import Optionalimport sempy_labs._icons as iconsdef update_direct_lake_model_lakehouse_connection(dataset: str,workspace: Optional[str] = None,lakehouse: Optional[str] = None,lakehouse_workspace: Optional[str] = None,😞"""Remaps a Direct Lake semantic model's SQL Endpoint connection to a new lakehouse.Parameters----------dataset : strName of the semantic model.workspace : str, default=NoneThe Fabric workspace name in which the semantic model exists.Defaults to None which resolves to the workspace of the attached lakehouseor if no lakehouse attached, resolves to the workspace of the notebook.lakehouse : str, default=NoneThe Fabric lakehouse used by the Direct Lake semantic model.Defaults to None which resolves to the lakehouse attached to the notebook.lakehouse_workspace : str, default=NoneThe Fabric workspace used by the lakehouse.Defaults to None which resolves to the workspace of the attached lakehouseor if no lakehouse attached, resolves to the workspace of the notebook.Returns-------"""workspace = fabric.resolve_workspace_name(workspace)if lakehouse_workspace is None:lakehouse_workspace = workspaceif lakehouse is None:lakehouse_id = fabric.get_lakehouse_id()lakehouse = resolve_lakehouse_name(lakehouse_id, lakehouse_workspace)# Check if lakehouse is validdfI = fabric.list_items(workspace=lakehouse_workspace, type="Lakehouse")dfI_filt = dfI[(dfI["Display Name"] == lakehouse)]if len(dfI_filt) == 0:raise ValueError(f"{icons.red_dot} The '{lakehouse}' lakehouse does not exist within the '{lakehouse_workspace}' workspace. "f"Therefore it cannot be used to support the '{dataset}' semantic model within the '{workspace}' workspace.")dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)dfP_filt = dfP[dfP["Mode"] == "DirectLake"]if len(dfP_filt) == 0:raise ValueError(f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models.")else:with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:shEx = get_shared_expression(lakehouse, lakehouse_workspace)try:tom.model.Expressions["DatabaseQuery"].Expression = shExprint(f"{icons.green_dot} The expression in the '{dataset}' semantic model has been updated to point to the '{lakehouse}' lakehouse in the '{lakehouse_workspace}' workspace.")except Exception as e:raise ValueError(f"{icons.red_dot} The expression in the '{dataset}' semantic model was not updated.") from eTry the above code. Simalarly you can repoint the reportsRegards,SrisakthiIf this helps, please mark is Accept As Solution
Hi HarderT,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.
Regards,
Vinay Pabbu
- HarderT1 year agoHelper II
Hi Anonymous,
the Problem now is when we change the connection it creates a new report and does not overwrite the old one.
- Anonymous1 year agoNot applicable
Hi HarderT,
Thats the Default behaviour. Power BI treats it as a new data source, which results in a new report being created instead of overwriting the existing one.
if you're using Power BI Desktop, you can try updating the connection string from within the file and republish it, which should overwrite the existing report.Regards,
Vinay Pabbu
- Srisakthi1 year agoSuper User
Hi HarderT ,
You can utilise Semantic Link Labs to repoint to new lakehouse.
import sempy.fabric as fabricfrom sempy_labs.directlake._get_shared_expression import get_shared_expressionfrom sempy_labs._helper_functions import (resolve_lakehouse_name,)from sempy_labs.tom import connect_semantic_modelfrom typing import Optionalimport sempy_labs._icons as iconsdef update_direct_lake_model_lakehouse_connection(dataset: str,workspace: Optional[str] = None,lakehouse: Optional[str] = None,lakehouse_workspace: Optional[str] = None,😞"""Remaps a Direct Lake semantic model's SQL Endpoint connection to a new lakehouse.Parameters----------dataset : strName of the semantic model.workspace : str, default=NoneThe Fabric workspace name in which the semantic model exists.Defaults to None which resolves to the workspace of the attached lakehouseor if no lakehouse attached, resolves to the workspace of the notebook.lakehouse : str, default=NoneThe Fabric lakehouse used by the Direct Lake semantic model.Defaults to None which resolves to the lakehouse attached to the notebook.lakehouse_workspace : str, default=NoneThe Fabric workspace used by the lakehouse.Defaults to None which resolves to the workspace of the attached lakehouseor if no lakehouse attached, resolves to the workspace of the notebook.Returns-------"""workspace = fabric.resolve_workspace_name(workspace)if lakehouse_workspace is None:lakehouse_workspace = workspaceif lakehouse is None:lakehouse_id = fabric.get_lakehouse_id()lakehouse = resolve_lakehouse_name(lakehouse_id, lakehouse_workspace)# Check if lakehouse is validdfI = fabric.list_items(workspace=lakehouse_workspace, type="Lakehouse")dfI_filt = dfI[(dfI["Display Name"] == lakehouse)]if len(dfI_filt) == 0:raise ValueError(f"{icons.red_dot} The '{lakehouse}' lakehouse does not exist within the '{lakehouse_workspace}' workspace. "f"Therefore it cannot be used to support the '{dataset}' semantic model within the '{workspace}' workspace.")dfP = fabric.list_partitions(dataset=dataset, workspace=workspace)dfP_filt = dfP[dfP["Mode"] == "DirectLake"]if len(dfP_filt) == 0:raise ValueError(f"{icons.red_dot} The '{dataset}' semantic model is not in Direct Lake. This function is only applicable to Direct Lake semantic models.")else:with connect_semantic_model(dataset=dataset, readonly=False, workspace=workspace) as tom:shEx = get_shared_expression(lakehouse, lakehouse_workspace)try:tom.model.Expressions["DatabaseQuery"].Expression = shExprint(f"{icons.green_dot} The expression in the '{dataset}' semantic model has been updated to point to the '{lakehouse}' lakehouse in the '{lakehouse_workspace}' workspace.")except Exception as e:raise ValueError(f"{icons.red_dot} The expression in the '{dataset}' semantic model was not updated.") from eTry the above code. Simalarly you can repoint the reportsRegards,SrisakthiIf this helps, please mark is Accept As Solution
- Anonymous1 year agoNot applicable
Hi @HarderT,
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.Regards,
Vinay Pabbu