I am trying to get the total amount for each ID on each date.
Example data:
ID Date Amount
619|RENE ABERIA 2017-01-03 418.80
619|RENE ABERIA 2017-01-03 497.48
619|RENE ABERIA 2017-01-03 29.13
620|JAMES APRECIO 2017-01-03 460.70
620|JAMES APRECIO 2017-01-03 76.33
620|JAMES APRECIO 2017-01-04 460.70
620|JAMES APRECIO 2017-01-04 59.32
620|JAMES APRECIO 2017-01-06 460.70
This is all in a datagridview and have plenty of rows. For "619" on "2017-01-03" I have 3 different amounts e.g. 418.80, 497.48, and 29.13. I want to total this amount and place it below the last entry as shown below.
ID Date Amount
619|RENE ABERIA 2017-01-03 418.80
619|RENE ABERIA 2017-01-03 497.48
619|RENE ABERIA 2017-01-03 29.13
Total: 945.41
620|JAMES APRECIO 2017-01-03 460.70
620|JAMES APRECIO 2017-01-03 76.33
Total: 537.03
620|JAMES APRECIO 2017-01-04 460.70
620|JAMES APRECIO 2017-01-04 59.32
Total: 520.02
620|JAMES APRECIO 2017-01-06 460.70
Total: 460.70
I think I have to use a FOR LOOP to go to each row but I don't know how to go about it or continue. Below is what I have so far and, obviously, it's still a long way to being complete.
private void GetTotalShareForDay()
{
string laborerOrig = null;
string laborerCopy = null;
string dateOrig = null;
string dateCopy = null;
var share = 0.0;
for (var i = 0; i < dgvSummary.Rows.Count; i++)
{
if (i == 0)
{
laborerOrig = dgvSummary.Rows[i].Cells[0].Value.ToString();
dateOrig = dgvSummary.Rows[i].Cells[1].Value.ToString();
laborerCopy = laborerOrig;
dateCopy = dateOrig;
share += Convert.ToDouble(dgvSummary.Rows[i].Cells[5].Value);
Console.WriteLine(dateOrig + @" - " +dgvSummary.Rows[i].Cells[0].Value + @" - " + share);
continue;
}
else
{
laborerOrig = dgvSummary.Rows[i].Cells[0].Value.ToString();
dateOrig = dgvSummary.Rows[i].Cells[1].Value.ToString();
if (laborerCopy == laborerOrig && dateCopy == dateOrig)
{
share += Convert.ToDouble(dgvSummary.Rows[i].Cells[5].Value);
Console.WriteLine(dateOrig + @" - " + dgvSummary.Rows[i].Cells[0].Value + @" - " + share);
}
else if (laborerCopy == laborerOrig && dateCopy != dateOrig)
{
dateCopy = dateOrig;
share = Convert.ToDouble(dgvSummary.Rows[i].Cells[5].Value);
Console.WriteLine(dateOrig + @" - " + dgvSummary.Rows[i].Cells[0].Value + @" - " + share);
}
else
{
laborerCopy = laborerOrig;
dateCopy = dateOrig;
share = Convert.ToDouble(dgvSummary.Rows[i].Cells[5].Value);
Console.WriteLine(dateOrig + @" - " + dgvSummary.Rows[i].Cells[0].Value + @" - " + share);
}
}
}
}
This is different from the issue in "how I can show the sum of in a datagridview column?" because that example only sums everything in that column. What I need is to sum the values of the column with the same ID and the same date.
Your help is greatly appreciated.