`Measure-Object Sum`未返回数组的总和。

huangapple go评论84阅读模式
英文:

Measure-object Sum not returning Sum of array

问题

如果我查询一个列,我会得到一个数字列表作为返回。如果我将它放入 Measure-Object 中,Sum 不正确?

如何最有效地对这个数字列表求和?

  1. $array.'Profit'

返回...

  • 0.000
  • 0.000
  • 0.000
  • 2387.500
  • 1610
  1. $array.'Profit' | measure-object -property length -minimum -maximum -sum -average

返回一个数字列表...

  • Count : 5
  • Average : 5.4
  • Sum : 27
  • Maximum : 8
  • Minimum : 4
  • Property : Length

Sum 似乎不正确?

我在这里漏掉了什么?

感谢您的时间。

英文:

I have an array that If I query a column, I get a list of numbers in return. If I place into Measure-Object, the Sum is not correct?

What is most efficient way to Sum this list of numbers?

  1. $array.'Profit'

Returns...

  • 0.000
  • 0.000
  • 0.000
  • 2387.500
  • 1610
  1. $array.'Profit' | measure-object -property length -minimum -maximum -sum -average

Returns a list of numbers...

  • Count : 5
  • Average : 5.4
  • Sum : 27
  • Maximum : 8
  • Minimum : 4
  • Property : Length

Which the Sum doesn't add up?

What am I missing here?

Thank you for your time

答案1

得分: 2

  1. 如果我理解您的示例正确,`Profit` 是每个数组元素中的单一属性,去掉对长度的引用(`-property length`):

$array = 1.1, 2.1, 3.1 | % { [pscustomobject]@{profit = $_} }

$array.profit | measure -minimum -maximum -sum -average

Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property :

  1. 或者

$array | measure -property profit -minimum -maximum -sum -average

Count : 3
Average : 2.1
Sum : 6.3
Maximum : 3.1
Minimum : 1.1
Property : profit

  1. 最小值、最大值、总和和平均值都是 `[double]` 类型的实例。

$array | measure -property profit -minimum -maximum -sum -average | % sum |
% gettype

IsPublic IsSerial Name BaseType


True True Double System.ValueType

英文:

If I take your example right, Profit being a single property in each array element, taking off the reference to length (-property length):

  1. $array = 1.1, 2.1, 3.1 | % { [pscustomobject]@{profit = $_} }
  2. $array.profit | measure -minimum -maximum -sum -average
  3. Count : 3
  4. Average : 2.1
  5. Sum : 6.3
  6. Maximum : 3.1
  7. Minimum : 1.1
  8. Property :

Or

  1. $array | measure -property profit -minimum -maximum -sum -average
  2. Count : 3
  3. Average : 2.1
  4. Sum : 6.3
  5. Maximum : 3.1
  6. Minimum : 1.1
  7. Property : profit

Minimum, maximum, sum, and average end up as instances of type [double].

  1. $array | measure -property profit -minimum -maximum -sum -average | % sum |
  2. % gettype
  3. IsPublic IsSerial Name BaseType
  4. -------- -------- ---- --------
  5. True True Double System.ValueType

huangapple
  • 本文由 发表于 2023年6月25日 23:49:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定