This is the answer for anyone wondering
maxNumberOfVMs = 20; // maximum number of VMs you want
samplePercentThreshold = 0.7;
sampleDuration = TimeInterval_Minute * 3;
// Get the last sample
$sample = (avg($CPUPercent.GetSample(sampleDuration)));
// If the average CPU usage was more than 70%, increase nodes by one, if not true keeps as is
$TargetDedicated = ($sample >= samplePercentThreshold ? $TargetDedicated +1 : $TargetDedicated);
// If the average CPU usage is below 20% decrease nodes by one, if not true keep as is
$TargetDedicated = ($sample <= 0.2 ? $TargetDedicated - 1 : $TargetDedicated);
// Always keep the number of nodes under the maximum
$TargetDedicated = min($TargetDedicated, maxNumberOfVMs);