Forum Discussion
List Generate Average as record;
- 8 months ago
I'm not sure what you are asking here.
Clearly in the code z and y are always the same.
But what is this? It makes no sense. Where are you getting this from?
z / 2 <> z = y/2
You can't say a thing (z/2) is not equal (or equal) to another thing (z=y/2).
You can't have an assignment on one side of a logical test like this
Again not sure how esle to explain this other than how I have.
z / 2 <> z = y/2 makes no sense mathematically and I don't know what you are trying to do there.
Phil
Hi Dicken,
Let me know if thats it are you expecting for:
Script tested:
let
alist = List.Numbers(1, 20, 1),
result = List.Generate(
() => [x = 1, asum = alist{0}, avg = alist{0}],
each [x] < List.Count(alist),
each [
x = [x] + 1,
asum = [asum] + alist{[x]-1},
avg = [asum] / [x]
]
)
in
result
My oppinion:
First Case (Works as Expected):
- asum = cumulative sum up to current x
- avg = cumulative sum divided by current count
This gives the correct running average.
Second Case (Incorrect Result):
avg = ([avg] + alist)
- avg is not the sum; it is already an average from the previous step.
- Adding alist{x-1} to an average does not produce a correct cumulative sum.
- Then dividing by x again compounds the error.
Because avg is not a sum, so adding a new element to it does not represent the cumulative total. The correct formula must always reference the cumulative sum (asum), not the previous average.
If this response was helpful in any way, Iād gladly accept a šmuch like the joy of seeing a DAX measure work first time without needing another FILTER.
Please mark it as the correct solution. It helps other community members find their way faster (and saves them from another endless loop š.