Nested Dataset and the Query operator

Suppose I have the following Dataset, one of whose columns is a nested Dataset:

ClearAll[dat];
dat = Dataset[{
<|
"a" -> 2,
"b" -> 3,
"c" -> Dataset[{<|"c1" -> 2, "c2" -> 4|>,  <|"c1" -> 3, "c2" -> 6|>}]
|>,
<|
"a" -> 3,
"b" -> 4,
"c" -> Dataset[{<|"c1" -> 3, "c2" -> 6|>, <|"c1" -> 4, "c2" -> 8|>}]
|>,
<|
"a" -> 4,
"b" -> 1,
"c" -> Dataset[{<|"c1" -> 4, "c2" -> 8|>, <|"c1" -> 1, "c2" -> 2|>}]
|>,
<|
"a" -> 4,
"b" -> 2,
"c" -> Dataset[{<|"c1" -> 4, "c2" -> 8|>, <|"c1" -> 2, "c2" -> 4|>}]
|>
}];


This gives me the following:

Now I want to transform dat in the following way:

dat // Query[All, <|
"A" -> "a", "B" -> "b",
"T2" -> (Key["c"] /* (#[All, "c2"] &) /* Normal /* Total)
|>]


This gives me the expected result:

However, when I run the following:

dat // Query[All, <|
"A" -> "a", "B" -> "b",
"T2" -> (Key["c"] /* Query[All, "c2"] /* Normal /* Total)
|>]


I get zeros in the last column instead:

So, what gives? Why does Query not work for the inner Dataset? Is this just an idiosyncrasy with which I must live? Or is there are deeper model of execution which I am failing to understand?

• You are missing a # in the last evaluation – Giovanni Baez Jul 5 '18 at 23:07