Skip to main content
deleted 33 characters in body
Source Link
Alan
  • 13.8k
  • 21
  • 41

Total the extracted amounts.Edited in response to change in question added in a comment:

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5]StringTemplate["Stage``"]@RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Totalgrp /@= GroupBy[dataGroupBy["Supplier"]
data[grp, #Supplier &Total, Map[#["Amount"] &]]"Amount"]

Edited in response to change in question:

Your comment says you only want to total over a Stage1 and Stage 2, so select for these.

sel = Select["Stage1" == #Stage || "Stage2" == #Stage &]
grp = GroupBy["Supplier"]
data[sel][grp, Total, "Amount"]

Total the extracted amounts.

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Total /@ GroupBy[data, #Supplier &, Map[#["Amount"] &]]

Edited in response to change in question:

Your comment says you only want to total over a Stage1 and Stage 2, so select for these.

sel = Select["Stage1" == #Stage || "Stage2" == #Stage &]
grp = GroupBy["Supplier"]
data[sel][grp, Total, "Amount"]

Edited in response to change in question added in a comment:

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> StringTemplate["Stage``"]@RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
grp = GroupBy["Supplier"]
data[grp, Total, "Amount"]

Your comment says you only want to total over a Stage1 and Stage 2, so select for these.

sel = Select["Stage1" == #Stage || "Stage2" == #Stage &]
data[sel][grp, Total, "Amount"]
respond to comment
Source Link
Alan
  • 13.8k
  • 21
  • 41

Total the extracted amounts.

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Total /@ GroupBy[data, #Supplier &, Map[#["Amount"] &]]

Edited in response to change in question:

Your comment says you only want to total over a Stage1 and Stage 2, so select for these.

sel = Select["Stage1" == #Stage || "Stage2" == #Stage &]
grp = GroupBy["Supplier"]
data[sel][grp, Total, "Amount"]

Total the extracted amounts.

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Total /@ GroupBy[data, #Supplier &, Map[#["Amount"] &]]

Total the extracted amounts.

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Total /@ GroupBy[data, #Supplier &, Map[#["Amount"] &]]

Edited in response to change in question:

Your comment says you only want to total over a Stage1 and Stage 2, so select for these.

sel = Select["Stage1" == #Stage || "Stage2" == #Stage &]
grp = GroupBy["Supplier"]
data[sel][grp, Total, "Amount"]
Source Link
Alan
  • 13.8k
  • 21
  • 41

Total the extracted amounts.

data = Dataset@Table[Association[
     "Sector" -> RandomChoice[{"Energy", "Env"}],
     "Supplier" -> StringTemplate["N``"]@RandomInteger[5],
     "Stage" -> 10*RandomInteger[5],
     "Amount" -> 1000*RandomInteger[200]
     ], 100];
Total /@ GroupBy[data, #Supplier &, Map[#["Amount"] &]]