It's quite simple. All what you need to do is to group data by
PREP
field. Please, check out below solution:
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("BL", typeof(int)),
new DataColumn("PREP", typeof(string)),
new DataColumn("NBLIG", typeof(int)),
new DataColumn("QTY", typeof(int)),
new DataColumn("ERRTYPE", typeof(string))
});
dt.Rows.Add(new object[]{125485, "P1", 5, 125, "RNF"});
dt.Rows.Add(new object[]{189654, "P2", 12, 762, "RNF"});
dt.Rows.Add(new object[]{156985, "P2", 3, 36, "FNR"});
dt.Rows.Add(new object[]{219874, "P1", 36, 5423, "OTH"});
dt.Rows.Add(new object[]{123698, "P3", 6, 112, "OTH"});
dt.Rows.Add(new object[]{719736, "P1", 25, 998, "RNF"});
var result = dt.AsEnumerable()
.GroupBy(x=>x.Field<string>("PREP"))
.Select(grp=>new
{
PREP = grp.Key,
NB_BL = grp.Count(),
TOTLIG = grp.Where(x=>x.Field<string>("PREP")==grp.Key).Sum(x=>x.Field<int>("NBLIG")),
TOTQTY = grp.Where(x=>x.Field<string>("PREP")==grp.Key).Sum(x=>x.Field<int>("QTY")),
TOTRNF = grp.Where(x=>x.Field<string>("ERRTYPE")=="RNF").Count(),
TOTFNR = grp.Where(x=>x.Field<string>("ERRTYPE")=="FNR").Count(),
TOTOTH = grp.Where(x=>x.Field<string>("ERRTYPE")=="OTH").Count()
})
.ToList();