8 replaced GroupBy call by dataset query
source | link
FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the name of the first column, but the following works by reconstructing a new Dataset from the results of GroupBy:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &, 
  GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]]

enter image description here

edit

Following @VictorK. 's solution, the above query can be simplified a bit:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &,
  FEflag[GroupBy["userId"], Total, "A1flag"]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the name of the first column, but the following works by reconstructing a new Dataset from the results of GroupBy:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &, 
  GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the name of the first column, but the following works by reconstructing a new Dataset from the results of GroupBy:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &, 
  GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]]

enter image description here

edit

Following @VictorK. 's solution, the above query can be simplified a bit:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &,
  FEflag[GroupBy["userId"], Total, "A1flag"]]

enter image description here

7 added 1 character in body
source | link
FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the name of the first column names, but this hackthe following works by reconstructing a new Dataset from the results of GroupBy:

Dataset@KeyValueMap[AssociationKeyValueMap[<|"userId" -> #1, "sum" -> #2|> &, 
  GroupBy[FEflag, ("userId"->#["userId"]&)Key["userId"] -> Key["A1flag"], "sum"->Total[#]&]]Total]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the column names, but this hack works by reconstructing a new Dataset from the results of GroupBy:

Dataset@KeyValueMap[Association,
  GroupBy[FEflag, ("userId"->#["userId"]&) -> Key["A1flag"], "sum"->Total[#]&]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the name of the first column, but the following works by reconstructing a new Dataset from the results of GroupBy:

KeyValueMap[<|"userId" -> #1, "sum" -> #2|> &, 
  GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]]

enter image description here

6 added 183 characters in body
source | link
FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the column names, but this hack works by reconstructing a new Dataset from the results of GroupBy:

Dataset@KeyValueMap[Association,
  GroupBy[FEflag, ("userId"->#["userId"]&) -> Key["A1flag"], "sum"->Total[#]&]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

I don't know a pretty way of keeping the column names, but this hack works by reconstructing a new Dataset from the results of GroupBy:

Dataset@KeyValueMap[Association,
  GroupBy[FEflag, ("userId"->#["userId"]&) -> Key["A1flag"], "sum"->Total[#]&]]

enter image description here

FEflag = AssociationThread[{"userId", "A1flag"}, #] & /@
  {{5311, 1}, {5311, 1}, {5313, 1}, {5313, 1}, {5313, 1}, {5313, 0}} // Dataset

enter image description here

GroupBy[FEflag, First -> Last, Total]

enter image description here

The same result can be achieved more robustly with

GroupBy[FEflag, Key["userId"] -> Key["A1flag"], Total]

enter image description here

which makes fewer assumptions about the ordering of the columns.

I don't know a pretty way of keeping the column names, but this hack works by reconstructing a new Dataset from the results of GroupBy:

Dataset@KeyValueMap[Association,
  GroupBy[FEflag, ("userId"->#["userId"]&) -> Key["A1flag"], "sum"->Total[#]&]]

enter image description here

5 added FEflag definition
source | link
4 deleted 11 characters in body
source | link
3 added 69 characters in body
source | link
2 added 306 characters in body
source | link
1
source | link