Microsoft Fabric: Capacity Cost Management Part 3, Pause Capacity During Christmas with Azure Logic Apps

Microsoft Fabric: Capacity Cost Management Part 3, Pause Capacity During Christmas with Azure Logic Apps

In the first blog post of this series, I explained that we can Pause and Resume a Microsoft Fabric capacity from Azure Portal. In the second blog and its accompanying YouTube video, I showed you how to automate the Pause and Resume actions in Azure LogicApps so the capacity starts at 8:00 AM and stops at 4:00 PM. While I have already mentioned in those posts, it is worthwhile to mention again that these methods only make sense for PAYG (Pay-As-You-Go) capacities and NOT the Reservation capacities. While the method works fine, you may need more fine-tuning.

Managing operational costs becomes crucial for businesses leveraging Microsoft Fabric capacities when the holiday season approaches. This presents a unique challenge of maintaining efficiency while reducing unnecessary expenses, especially during Christmas when business operations might slow down or pause entirely.

In this post and video, I will extend the discussions from my previous blog and demonstrate how to optimise your Azure Logic Apps to manage Microsoft Fabric capacity during the Christmas holidays.

Extending the Logic Apps Workflow

Existing Setup Recap

In earlier discussions, we’ve explored using Azure Logic Apps to manage Fabric capacity effectively from 8:00 AM to 4:00 PM on regular business days and pausing operations afterwards. This setup ensures that we’re not incurring costs when the capacity isn’t needed, particularly from 4:00 PM to 8:00 AM the next morning, and throughout the weekends. I encourage you to check out my previous post for more information. This is how the existing solution looks like in Azure LogicApps:

Automating Microsoft Fabric Capacity with Azure LogicApps
Automating Microsoft Fabric Capacity with Azure LogicApps

Incorporating Holiday Schedules

The key to extending this setup for the Christmas period lies in integrating specific holiday schedules into your existing workflows using Workflow Definition Language which is used in Azure Logic Apps and Microsoft Flow. The following expression determines if the current date (in New Zealand Standard Time) falls within the period from December 25th of the current year to January 2nd of the next year:

and(
    greaterOrEquals(
        int(
            formatDateTime(
                convertFromUtc(
                    utcNow(), 
                    'New Zealand Standard Time'
                ), 
                'yyyyMMdd'
            )
        ), 
        int(
   concat(
    formatDateTime(
     utcNow()
     , 'yyyy'
     )
    , '1225'
    )
   ) 
    ), 
    lessOrEquals(
        int(
            formatDateTime(
                convertFromUtc(
                    utcNow(), 
                    'New Zealand Standard Time'
                ), 
                'yyyyMMdd'
            )
        ), 
        int(
   concat(
    add(
     int(
      formatDateTime(
       utcNow()
       , 'yyyy'
       )
      )
     ,1
     )
    , '0102'
    )
   )
  )
)

The following section explains how the expression works.

Overall Structure

The expression uses the and function to combine two conditions:

  1. Checking if the current date is greater than or equal to December 25th of the current year.
  2. Checking if the current date is less than or equal to January 2nd of the next year.

First Condition: Current Date >= December 25th

greaterOrEquals(
    int(
        formatDateTime(
            convertFromUtc(
                utcNow(), 
                'New Zealand Standard Time'
            ), 
            'yyyyMMdd'
        )
    ), 
    int(
        concat(
            formatDateTime(
                utcNow(), 
                'yyyy'
            ),
            '1225'
        )
    )
)
  1. utcNow(): Gets the current UTC date and time.
  2. convertFromUtc(utcNow(), 'New Zealand Standard Time'): Converts the current UTC date and time to New Zealand Standard Time.
  3. formatDateTime(convertFromUtc(utcNow(), 'New Zealand Standard Time'), 'yyyyMMdd'): Formats the converted date to a string in ‘yyyyMMdd‘ format.
  4. int(formatDateTime(...)): Converts the formatted date string to an integer.
  5. concat(formatDateTime(utcNow(), 'yyyy'), '1225'): Concatenates the current year with ‘1225’ to form a string representing December 25th of the current year.
  6. int(concat(...)): Converts the concatenated date string to an integer.
  7. greaterOrEquals(int(...), int(...)): Compares if the current date integer is greater than or equal to the integer representing December 25th of the current year.

Second Condition: Current Date <= January 2nd

lessOrEquals(
    int(
        formatDateTime(
            convertFromUtc(
                utcNow(), 
                'New Zealand Standard Time'
            ), 
            'yyyyMMdd'
        )
    ), 
    int(
        concat(
            add(
                int(
                    formatDateTime(
                        utcNow(), 
                        'yyyy'
                    )
                ), 
                1
            ), 
            '0102'
        )
    )
)

This part of the expression is very similar to the first condition, with the key difference being the comparison date:

  1. Add 1 to the current year:
   add(
       int(
           formatDateTime(
               utcNow(), 
               'yyyy'
           )
       ), 
       1
   )

This calculates the next year by adding 1 to the current year.

  1. Concatenate with ‘0102’:
   concat(
       add(...), 
       '0102'
   )

This creates a string representing January 2nd of the next year. The rest of the steps are the same as the first condition, converting the current date and the comparison date to integers and using lessOrEquals to check if the current date is less than or equal to January 2nd of the next year.

Combining Conditions

The and function combines the two conditions:

  1. The current date is greater than or equal to December 25th of the current year.
  2. The current date is less than or equal to January 2nd of the next year.

If both conditions are true, the overall expression returns true, indicating that the current date is within the specified holiday period.

Just remember, the code considers the Christmas period in New Zealand, so you need to change it to fit your scenario.

Modify the Previous Azure LogicApps Workflow

On Azure Portal, navigate to your Azure LogicApps and open the solution created before, then follow these steps:

  1. Click the (+) button to insert a new step between the Read a resource and Condition, Check Time of Day
  2. Click the Add and action option
  3. Search for Condition
  4. Click the Condition control
Add a new condition between actions in Azure LogicApps
Add a new condition between actions in Azure LogicApps
  1. Click the first condition text box and click the fx option to enter the expression
  2. Copy the expression from the previous section and paste it into the expression box
  3. Click the Add button
  1. Leave the operation to is equal to
  2. Type in true as its comparison value
  1. Rename the condition to Check if the date is in Xmas period
Add an expression to a condition
Add an expression to a condition
  1. Move the entire Condition, Check Time of Day to the False condition else action
Move an entire action to a condition else action
Move an entire action to a condition else action
  1. Right-click the Condition, Check if Status is Active condition and click the Copy Entire Action option
  2. Click the (+) button on the True condition action of the Check if the date is in Xmas period condition
  3. Click the Paste an action option
Copy and paste an entire action
Copy and paste an entire action
  1. Rename the copied condition and action

The final solution should look like below:

Azure LogicApps keeping Fabric capacity paused during Christmas
Azure LogicApps keeping Fabric capacity paused during Christmas

Do not forget to save the solution. When we run the final solution, the workflow checks the date to find out if we are currently in the Christmas period or not. Depending on the results, it either keeps the capacity running or

Conclusion

Adjusting your Azure Logic Apps to include a holiday schedule, particularly during Christmas, can significantly impact your operational costs and efficiency.

Stay tuned for more insights, and don’t forget to check out the previous videos on this topic if you haven’t already. They provide a solid foundation for understanding how to harness the full potential of Azure Logic Apps for fabric capacity management.

As always, do not forget to subscribe and leave your comments below.

Follow me on LinkedIn, YouTube, and @_SoheilBakhshi on X (formerly Twitter).

4 thoughts on “Microsoft Fabric: Capacity Cost Management Part 3, Pause Capacity During Christmas with Azure Logic Apps

  1. Thanks Soheil this helped a lot and really appreciate the details. while testing this logic app i have noticed that capacity administrator permissions are wiped when capacity is paused and resumed.

    1. Hi Elon,

      That’s great to hear the solution works for you.
      About the capacity admin permissions, this is not happening in my scenario.
      I am aware that the capacity scaling solution with LogicApps results in wiping the capacity admins, and I know what the issue is. However, it is not the case for the Pause/Resume solution. In my implementations, the capacity admin settings remain unchanged.
      My solution is not complete yet but I’m working on it, and I will prepare a concise post/YouTube video explaining it.

      So stay tuned.

  2. Hello Soheil,

    Thanks for the content and the example. Very useful! I do have a related question that I have been trying to get answered on the Microsoft site, and can’t seem to get one. So, if you know – how does the spreading of capacity usage work when you pause the capacity for a period of time. specifically, there are some workloads that spread over 24 hours. Are those tasks and usage still spread over 24 hours, or are they spread over the number of hours a capacity is running in a 24 hour period. So in your example, just for the 8 hours a day that the capacity is running? Thanks for any insight you have.

    1. Hi Jon,

      Thanks for the question.
      It’s one of those questions that requires a blog (or a series of blogs) to thoroughly address the matter.
      But to quickly answer your question, all the smoothing scheduled will fire before suspending the capacity, therefore, your capacity will remain running (the capacity status will turn to “Pausing” in the UI (Azure Portal)). So, you’ll expect to see a spike in the usage during this period. I currently am unsure how long the period takes but in my experience the longest took about 15 minutes.
      After the capacity is suspended (Paused), it stops running any activities, hence, no compute costs, however, we will still be changed for OneLake (storage).
      I will write a blog and record a video explaining it in more detail.
      So, stay tuned for that.
      For now, I hope the above would help.
      Cheers

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.