
Originally Posted by
Ken Puls
We're a bit spoiled with Excel that it treats empty cells as zeros, but in PQ, null <> 0, so it can't do math against them. (It's a bit frustrating, to be honest!)
If instead of:
Code:
each [201701]+[201702]+[201703]+[201704]+[201705]+[201706]+[201707]+[201708]+[201709]+[201710]+[201711]+[201712]
we use List.Sum:
Code:
each List.Sum({[201712], [201711], [201710], [201709], [201708], [201707], [201706], [201705], [201704], [201703], [201702], [201701]}
it appears you don't need to convert nulls to zero.
It also means we can tweak the query to cope with different fiscal periods; here we are in 2020, where such hard-coded column headers would throw an error.
If earlier on in the steps (before pivoting) you create a distinct list of values in the fiscal period column,:
Code:
rwhdrs = List.Distinct(#"Changed Type"[fiscalperiod])
you'll have a list of headers you can use as one of the List.Sum arguments, although not as direct as:
Code:
Table.ReplaceValue(#"Pivoted Column",null,0,Replacer.ReplaceValue,rwhdrs)
(now not needed) where rwhdrs is a list of text, the List.Sum wants to see a list of column fields so (and this is where I feel sure there's a more direct route to achieve this) you could use:
Code:
each List.Sum(Record.FieldValues(Record.SelectFields(_, rwhdrs)))
Note, this query took a minute or two to refresh, which could mean that it really could do with streamlining, or it may be due to my having more that 10 workbooks open, all with several Power Query queries in, amongst one or two other apps gobbling up my RAM.
Anyway, it's in the attached.
Bookmarks