Forum Discussion

RockliffeBI's avatar
RockliffeBI
Frequent Visitor
2 years ago

Power BI Notebooks - Persisting Variables Between Sessions

Hello, I'm trying to configure a Notebook to access some data from an API and save the resulting .json to a Datalakehouse.  It all works really nicely, but I want to configure it so that it polls the API only for data that I don't already have.  

 

I am setting a date range on the API call, using the current date at one end, at the other end I need to use the date that the notebook last successfully ran.  I can create that date in the Notebook, when it runs.  But is that value then available the next time the Notebook is run?

 

If it isn't, is there a simple alternative method to access that date, eg is the last run date available somewhere else or is do I ened to do something a bit hacky such as writing out the run date to another file in the Lakehouse that the Notebook can then pick up the date from the next time it runs?

 

Thanks!

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi RockliffeBI ,

     

    In Power BI Notebooks, by default, variables and their values are not retained between sessions.
    To retain variables between notebook sessions, you can consider the following methods:
    1. Use external storage:
    Store the date of the last run in an external storage location, such as a file or database in Datalakehouse. On each run, read the stored date from the external location and then update it after a successful run. In this way, the notebook can always reference the last run date from the external storage.
    2. Power BI Dataflow or Dataset:
    If your Power BI environment allows it, you can create a dataflow or dataset in Power BI to store the last run date. The notebook can then query this dataflow or dataset to retrieve the last run date and update it accordingly.


    Best Regards,
    Adamk Kong

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly