Archive for Azure

Automating VM Startup and Shutdown in Azure Resource Manager

This article summarizes the differences in automating starting up and shutting down virtual machines (VMs) between Azure Resource Manager and Classic mode.

Microsoft introduced Azure Resource Manager to facilitate management of your cloud assets in Azure, but given how new it is, it is often difficult to find exactly how to do that.

Earlier this year I created a new Azure VM for a client for use during business hours. The client requested the ability to automate the startup and shutdown of the VM when not in use, in order to save on costly compute time. Implementing a scheduled startup and shutdown of classic mode VMs has been documented and posted to various blogs. It was hard to find how to schedule startup and shutdown when the VMs are managed in the new Azure Resource Manager (ARM).

Classic method

The classic method of setting up auto-start up and shut down involves three steps: create an automation account and configure automation credentials, create runbooks that contain the PowerShell workflow scripts you want to execute, and attach one or more schedules to those runbooks. With Azure Resource Manager, the PowerShell workflow script you use in the second step is different.

In the classic method, you would use code similar to the following to set up your automation.

Startup script

workflow Start_MyClassicVM


$cred = Get-AutomationPSCredential -Name “MyAutomationCredential”

Add-AzureAccount -Credential $cred

Select-AzureSubscription “MySubscription”

$myVM = “MyVMName”

$serviceName = “MyService”

Start-AzureVM -ServiceName $serviceName -Name $myVM


First you fetch your credentials for your automation account and authenticate using the Add-AzureAccount method.

Once authenticated you designate which subscription context you are using. Often this might be called “Pay-As-You-Go” or “MSDN Subscription”.

You would then specify your service and run the Start-AzureVM command against your VM in that service.

Azure Resource Manager method

When using Azure Resource Manager you would adapt the following code.

Startup script

workflow Start_MyRmVM


$cred = Get-AutomationPSCredential -Name “AzureServiceAccount”

Add-AzureRMAccount -Credential $cred

Get-AzureRmSubscription -SubscriptionName “MySubscription” -TenantId “GUID-goes-here” | Set-AzureRmContext

$resourceGroup = “MyResourceGroup”

$myVM = “MyRmVm”

Start-AzureRmVM -ResourceGroupName $resourceGroup -Name $myVM


While configuring the automation account, runbooks and schedules remain the same, there are several key differences between automating startup of an ARM VM and a classic VM. Almost all of the methods you use with the Azure Resource Manager will contain “Rm” after the word “Azure” in their name. Also, the statement starting with “Get-AzureRmSubscription” is a bit more complex than in the classic version. Note that now, you need to know not just your subscription name, but also your Azure Active Directory Tenant ID. (Since I did not have access to the Azure Active Directory for my client’s subscription, I retrieved this GUID from the URL in the address bar after navigating to the Azure Active Directory in the classic portal. It’s possible, however, that this will change in the near future.) You then pipe the results of this new command, complete with the Tenant ID, to Set-AzureRmContext.

After that, rather than supplying a Service Name, you supply the name of your Azure Resource Group to the Start-AzureRmVM cmdlet.

Azure menu

Active directory link in Azure Portal menu

Shutdown script

To shut the VM down, the code is near-identical except for the last line:

Stop-AzureRmVM -ResourceGroupName $resourceGroup -Name $myVM -Force

Here is the full workflow script for shutdown.

workflow Stop_MyRmVM


$cred = Get-AutomationPSCredential -Name “AzureServiceAccount”

Add-AzureRMAccount -Credential $cred

Get-AzureRmSubscription -SubscriptionName ‘Pay-As-You-Go’ -TenantId “GUID”| Set-AzureRmContext

$resourceGroup = “MyResourceGroup”

$myVM = “MyRmVM”

Stop-AzureRmVM -ResourceGroupName $resourceGroup -Name $myVM -Force


KPI’s in Power BI: Not as hard as you think

Power BI just keeps getting better. The addition of the KPI visual to the standard palette is just another example in a long line of improvements, and the subject of this quick article.

Key Performance Indicators have been around long before the computer age. Show of hands: Who has ever browsed the new car showroom and NOT looked at the window stickers listing the vehicles’ MPG ratings? I thought not. While maybe not a true KPI as explained by Gerke & Associates, Inc here, Miles per Gallon is something we all understand when talking about the performance metric of a car. Most cars now come with computerized displays that will show instantaneous MPG, or an average over time. Keep these in mind when we transition this discussion over to Power BI.

In SQL Server Analysis Server cubes, you had the ability to create KPI’s inside the cube. They could then be browsed by the tool to which it was connected, something such as an Excel Pivot Table. Thought slightly different, KPI’s were also available in Analysis Server Tabular Models and Excel PowerPivot, both precursors to the Power BI Desktop.

But data analysts and modelers may experience premature disappointment to find that there is no way to create a KPI when using the Power BI Desktop designer. Knowing it was there in Excel PowerPivot models doesn’t help. It was there before, why did they take it out? Enter the KPI VISUAL.

KPI on Palette

By selecting this visual, you can create a KPI out of any metric in your model. It has three simple fields in the designer to define its appearance: Indicator, Trend axis, and Target goals. Let’s take a look at each of these in turn.

  • Indicator: This is the aggregated column or measure being considered. It could be as simple as the Sum of Sales. You do NOT need to slice this metric down to the latest value, such as [Sum of Sales for the last full month] or anything crazy like that. The base metric will suffice. The reason is explained below.
  • Trend axis: Grab a date type field for this (obviously) and (not so obviously) select the granularity: year, month, etc. Doing so will tell the KPI visual how you want to aggregate the Indicator metric over time.

At this point, your KPI should display two things: a black number and a grey shaded area in the background. We’ll explain all this at the end.


  • Target goal: This can also be an aggregated column or measure similar to the Indicator. If you don’t have one, it’s easy to create a ‘static’ goal by adding a new Measure with a simple static value such as: “KPI Goal = 100”, which is what I did for this demo.

Now, there’s only two options when you get all those things set: either it looks right, or it doesn’t. Consider the following two KPI Visuals from Power BI, both created from the same set of data, both using the same field settings.

KPI compare

The green one on the left I can tell you is how it is supposed to look based on the data I entered. It’s easy to see in the 6 rows that there has been a steady increase over the last 4 years.

KPI Data

So why did my initial attempt at a KPI result in the red one on the right? Apparently there is a dependency on the order in which the KPI is designed. If you selected a metric to add to your canvas first, and then decided to switch it to a KPI, you may get erroneous results. If, however, you start by adding an empty KPI to the canvas and then populating the three fields, you will probably see what you expect. If it doesn’t look right, the fix is quite simple really: remove the Indicator field and re-add it! It may be quirky, but it works.

Now let’s talk about all the pieces of information contained in this one (now correctly formatted) KPI visual. Referring to the green version on the left above, the bold number 120 corresponds to the value calculated (probably summed) for the latest point of the Trend Axis. Based on my data, that is the point for 1/1/1015. Typically, data would be spread over may dates over the years, but the aggregation of the Indicator, and the granularity of the Trend axis will determine the latest point to be displayed. The shaded green area is the trend plot for the Indicator. This shows a decrease at the very beginning, but steady increase after that. Next we see the green check-mark and green shade, indicating that this point is above the goal. (Using the format menu for the KPI you can reverse this if a lower number is better.) Finally, the small black text below the Indicator shows us the Goal, and the distance from that goal.

With this type of control in your hands, you can easily create KPI’s that display the same Indicator, but for different time slices such as by year, quarter, month, week, or day, depending on your needs.

Want to learn about some additional features in Power BI. View our series on Row Level Security in Power BI:

Part One

Part Two

Applied Machine Learning: Optimizing Patient Care in Hospitals, Profitably

Why are so many industries exploring Machine Learning as a means of delivering innovation and value?  In my view, the technology speaks to a primitive urge – machine learning is like having a crystal ball, telling you what will happen next.  For a business, it can convey information about a customer before they introduce themselves.  On a personal level, when I consider what I would like to have information about in advance, the first thing that springs to mind is obvious: my health.  Am I about to get sick?  How can I improve my wellness and overall health?  If you are wearing a Fit-Bit right now, then you probably agree with me.

In my last blog, I shared some real-world examples for how the Hospitality Industry applies Machine Learning.  What about Health Care and Hospitals?  While hospitals have similar challenges, in that they accommodate guests who stay overnight, the objectives in health care are quite different, and changing rapidly.   The Affordable Care Act is driving new business models, incentivizing outcome based reimbursement as opposed to volume based reimbursement.  Unlike hotels, today’s hospitals are interested in ensuring their guests do not have to return, at least not in the short term.   They also need to manage costs in a way they have not been incentivized to do in the past.  Hospitals across the country are considering how predictive analytics can have a  meaningful impact on operations, leading to improved patient health and improving the bottom line.

The cost savings opportunity for health care providers is startling. Here are just three examples:

Reducing Hospital Readmissions – in 2014, Medicare fined 2,610 hospitals $428 million for having high hospital readmission rates. Leaving actual fines aside, industry analysts estimate that the overall cost of preventable readmissions approaches $25 Billion annually. As a result, hospital systems all over the nation are mobilizing to intervene, using ML to identify risk factors which are highly predictive of readmission. Carolinas Healthcare System, partnering with Microsoft, did just that. Using data from 200,000 patient-discharge records, they created a predictive model deliver customized discharge planning, saving the hospital system hundreds of thousands of dollars annually. Read the article in Healthcare IT News.

Clinical Variation Management – Mercy Hospital is partnering with Ayasdi to find the optimal care path for common surgical procedures. Using knee replacement as an example, the Clinical Variation Management software helps hospital administrators find clusters of patient outcomes, then enables the exploration of those clusters in order to correlate a metric (i.e. Length of Stay) with a certain regiment or activity. Watch this video to learn how Mercy Hospital saved $50 million by applying Machine Learning to an extremely common procedure.

Improving Population Health – Dartmouth Hitchcock, a healthcare network affiliated with Dartmouth University, is piloting a remote monitoring system for patients requiring chronic care. 6,000+ patients are permitting the hospital to collect biometric data (i.e. blood pressure, temperature, etc.) in order that nurses and health coaches can monitor their vital signs, and machines can predict good days and bad days. Quite the opposite of hospitality: Dartmouth Hitchcock is trying to keep the guests from needing to checking in! Read more about the Case Study from Microsoft.

Are machines taking over for physicians? No. The Patient – Physician relationship remains (and I think will always remain) central to the delivery of personal health care. However, it seems clear that ACA is providing significant rewards to health care providers who manage population risk better. Machines can help here: through data, machine learning can find risk “hiding in the data”.

Contact Blum Shapiro Consulting to learn more about how Azure Machine Learning can curtail hospital readmissions, identify variations in common clinical procedures and improve patient population health.

Applied Machine Learning – Hospitality and Hotel Management

Machine Learning, or Predictive Analytics, is in common use in the travel and hospitality industry.  Online travel sites such as Expedia, Priceline and Trip Advisor have been putting data to use for over a decade, and they are very good at selling us stuff with Machine Learning.  They start by figuring out what someone will pay (relative to other customers) for a travel service, classifying preferences for all of the travel services they have available to sell, and recommending the next thing a website visitor need.  Flying to Vegas you say?  It’s very likely a hotel or car rental is in your future.  But which hotel offers will keep you on their site, buying from Expedia and not Expedia’s competitors?  Do you expect a premium hotel experience?  Do you need a Fiat or a GMC Acadia?  Are you a fan of Blue Man Group, Celine Dion or Penn and Teller?

And they usually get it right! They are using what is called a Recommendation Engine in order to guide customers through a series of buying decisions, based upon patterns and preferences which are similar to other customers.  Underneath, it’s just math, but the impact is undeniable.  It enables companies to predict what their customers want, and then (this is the critical piece) anticipate and deliver a response to that want, at a time when a customer truly needs it and is willing to pay for it.  Right thing, right place, right time.

Recommender is one of four core Machine Learning problems.  These four problems represent what ML can solve.  Now let’s apply Machine Learning to another business model within the Hospitality vertical: Hotel Management.  Is machine learning relevant to hotels?   If an algorithm can anticipate a guest’s need, what can hotel staff do with that information? The answer is: create a customer for life.

One common misconception about Machine Learning is that, in order to produce any useful insights, you need tons and tons of data (or, Big Data).  Property Management Systems (PMS) used by hotels and hotel groups are proving this wrong: they are using ML on a small scale to manage revenues, improve profitability and delight their customers.  Here are three examples of how hotel and property management groups are using Machine Learning to manage revenue today.

Market Segmentation – Customer segmentation is not a new thing.    We understand the difference between family vacationers and business travelers – those are big segments. But Machine Learning goes further, helping companies discover segments they may not realize existed. Which customers want to be near the pool, and which ones need three morning papers before they can even get dressed in the morning? Armed with this knowledge, hotels understand what matters to guests, at the individual level, enabling them to anticipate their needs immediately. Even more, hotels can understand key characteristics of their most profitable customers, and recognize the next one when they login to the online reservation site.

Demand Forecasting – what kinds of services will be in demand throughout the year? Can a hotel optimize room offerings to suit changing demand patterns, and perform renovations or scheduled maintenance in a way that has no net impact on profitability? While hotels may have limited ability to grow or shrink their inventory of rooms, management can optimize resource needs in order to respond to predicted demand levels.

Price Optimization – airlines understand very well that different customers are happy to pay different prices for the same airplane seat.  The same is true for hotel rooms.  Often, profitable customers are ones who are least price sensitive, but some are quite price sensitive – choosing to spend their money on other hotel services offered.

Machine Learning may seem intimidating, especially if you are assuming you’ll need Big Data and massive computing power in order to yield an investment.  Actually, the key ingredient is knowledge of your industry, and what you, as a services provider, can offer customers.  Most hotels and hotel groups have enough core guest information to begin deriving valuable insights and begin competing for customers in the new world of data.

Contact Blum Shapiro Consulting to learn more about how Azure Machine Learning can deliver these kind of predictive capabilities to your business, leading to sustained customer loyalty and profitable business outcomes.