Am trying to use a linq query to do a pivot table but am getting this error:
Assign: Input array is longer than the number of columns in this table.
This the resource I’ve been trying to follow:
Below is the linq query am trying to use:
(From row In dtBandPushing.AsEnumerable
Group row By Key = New With{
Key.TERMINAL = row.item("TERMINAL"),
Key.COMMISSION_EARNED =row.ITEM("COMMISSION_EARNED")
} Into grp = Group
Select dtBandPushing.LoadDataRow(New Object(){
Key.TERMINAL,
Key.COMMISSION_EARNED,
grp.Count()},True)
).CopyToDataTable
Add new data column (object type) to dtBandPushingGrouped using the Add Data Column Activity
Assign
dtBandPushingGouped =
(
From row In dtBandPushing.AsEnumerable
Group row By
k1 = row("TERMINAL"),
k2 = row("COMMISSION_EARNED")
Into grp = Group
Select dtBandPushingGrouped.Rows.Add({k1, k2, grp.Count()})
).CopyToDataTable
@hemanth.bhat,
Maybe to add more context to this @kumar.varun2’s linq query worked but I don’t know why he appends another column to the DataTable and on writing the data to an excel file I get that error of Failed setting the current sheet to: Export in workbook
(
From row In dt_Data.AsEnumerable
Group row By k = row("TERMINAL")
Into grp=Group
Select dt_Data.LoadDataRow({k, grp.Sum(Function(gr) CDbl(gr("COMMISSION_EARNED")))}, True)
).CopyToDataTable