Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Vienna from September 15-18, 2025, for the ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM. Get registered

Reply
tan_thiamhuat
Helper V
Helper V

Notebook -- exited gracefully

can I check how is it possible to exit a notebook gracefully with 

mssparkutils.notebook.exit when certain condition is met, and the rest of the code in the below cells are not executed.
 
Thanks.
1 ACCEPTED SOLUTION
burakkaragoz
Community Champion
Community Champion

Hi @tan_thiamhuat ,

 

Yeah, you can totally do that. If you use mssparkutils.notebook.exit inside a cell, it’ll stop the notebook right there and none of the cells below will run after that. Just put your condition check at the top of the cell, and call notebook.exit when you want to stop. For example:

Python
 
if some_condition:
    mssparkutils.notebook.exit("Stopping execution because condition met")
# whatever code below here won’t get executed if the exit is called

It doesn’t matter if you have more cells after, they just won’t be executed once exit runs. That’s how I usually handle early exits when I need to.

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

View solution in original post

1 REPLY 1
burakkaragoz
Community Champion
Community Champion

Hi @tan_thiamhuat ,

 

Yeah, you can totally do that. If you use mssparkutils.notebook.exit inside a cell, it’ll stop the notebook right there and none of the cells below will run after that. Just put your condition check at the top of the cell, and call notebook.exit when you want to stop. For example:

Python
 
if some_condition:
    mssparkutils.notebook.exit("Stopping execution because condition met")
# whatever code below here won’t get executed if the exit is called

It doesn’t matter if you have more cells after, they just won’t be executed once exit runs. That’s how I usually handle early exits when I need to.

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.