Skip to content

Instantly share code, notes, and snippets.

@dandohotaru
Created February 10, 2018 22:51
Show Gist options
  • Save dandohotaru/4b9586822907091313add34ce7b9f3f5 to your computer and use it in GitHub Desktop.
Save dandohotaru/4b9586822907091313add34ce7b9f3f5 to your computer and use it in GitHub Desktop.
//+---------------------------------+
//| Name PValue RValue NValue Group |
//+---------------------------------+
//| Low 100 600 300 Car |
//| High 900 400 700 Car |
//| Low 200 300 500 Truck|
//| High 800 700 500 Truck|
//+---------------------------------+
void Main()
{
var kpis = new[]{
new KPI{Group="Car", Name="Low",PersonalValue=100, RegionalValue=600, NationalValue=300},
new KPI{Group="Car", Name="High",PersonalValue=900, RegionalValue=400, NationalValue=700},
new KPI{Group="Truck", Name="Low",PersonalValue=200, RegionalValue=300, NationalValue=500},
new KPI{Group="Truck", Name="High",PersonalValue=800, RegionalValue=700, NationalValue=500},
};
var groups = from kpi in kpis
group kpi by kpi.Group into groupings
let names = groupings.Select(p => p.Name)
let pvalues = groupings.Select(p => p.PersonalValue)
let rvalues = groupings.Select(p => p.RegionalValue)
let nvalues = groupings.Select(p => p.NationalValue)
select new
{
Key = groupings.Key,
Names = string.Join(", ", names),
PValues = string.Join(", ", pvalues),
RValues = string.Join(", ", rvalues),
NValues = string.Join(", ", nvalues),
};
groups.Dump();
}
public class Customer
{
public String Code { get; set; }
public List<KPI> KPIs { get; set; }
}
public class KPI
{
public String Name { get; set; }
public int PersonalValue { get; set; }
public int RegionalValue { get; set; }
public int NationalValue { get; set; }
public String Group { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment