Asked by:
Extracting percent difference
General discussion

I think you really want:
$day1 = (dir $path ?{$_.LastWriteTime gt [datetime]::Today.AddDays(3) and $_.LastWriteTime lt [datetime]::Today.AddDays(2)}).Count
The math is:
$day1/$day2 gt .25
\_(ツ)_/
It was just a hint, not the solution. :)
Although i must admit, that using calculate property was not necessary there, so my example was not correct (datetime comparison was right though)
All replies





Oops. My formual should be:
1  ($day1/$day2) gt .25
\_(ツ)_/
So.. when 1 day is 50logs, second day is 70 logs.. then its .28 => your statement is correct.
What about 1 day 70logs, second 50 logs.. then its 0.4, right? :) Therefore your formula needs some more tweaking as were looking for 25% differency.. no matter if second day count Is higher or lower ..
 Edited by Mekac Friday, October 19, 2018 8:17 AM

No. You have to understand the mathematical concept of percent difference. Greater than 25% more means day 2 is more than 1.25.
Look at it this way.
$day2/$day1 gt 1.25
which is probably a clearer way of stating the question. The result of the left side is alwys greater than 1.25 when day 2 has more than 1.25 times as many files.
note that
$day2/$day1 eq 1
means that they are equal when it is true.
Another way of saying this is:
if $day2/$day1 is less than 0 or greater than then it is not equal.
The following:
$day2/$day1 gt 1.25
means that any time day 2 is more than 25% greater the expression is true.
Logic. It is what makes computers work. It is a fundamental pattern in programming.
This is all based on junior high school math so everyone should know it cold. Right?
Of course we can just invert this for more fun.
$day1/$day2 lt .75
Which is the same test.
1/($day1/$day2) 1 gt .25
$day1/$day2 lt .75
$day2/$day1 gt 1.25Are all the same test and are equivalent. They al test for the same condition.
\_(ツ)_/
 Edited by jrv Friday, October 19, 2018 8:59 AM


I should explain.
1/($day1/$day2)
This gets the inverse of the ratio.
1/($day1/$day2) 1 gt .25
subtract one to get the match to normalize at .25.
When $day2 is greater than $day the result is always positive. When $day1 is greater than 2 time $day2 the result is always negative.
This is why this formula is easier to use and understand as well as its variation (1).
$day2/$day1 gt 1.25
Note that a percent is not a numeric type but are a convenience added for display and obtained by multiplying by 100 and adding %.
\_(ツ)_/
 Edited by jrv Friday, October 19, 2018 9:08 AM
