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

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
  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
  1. Move the entire Condition, Check Time of Day to the False 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
  1. Rename the copied condition and action

The final solution should look like below:

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).