So I have a csv file with rows of data called "opportunities.csv"
This file is in the _data folder of my Jekyll site
client,opp,person,status
Oracle,"New thing five","Mary Smith",lead
Oracle,"Data plan","Sue Curry",lead
Oracle,"Migration 2019","Sue Curry",lead
IBM, "Platform assessment","Jane Campton",lost
I'd like to display the number of leads per person:
Mary Smith 1 lead
Sue Curry 2 lead
Jane Campion 0 lead
So, for each "person" in "site.opportunities" count the number of rows for each instance of "person" where "status" = "lead"
I now this involves incrementing counters inside nested for loops but I just can't seem to get it working.
I could change the data file format to json or yml but in my current use case I have other non-technical team members editing a csv file in excel so that's a given here.
You can do this with group_by
and where
filters :
{% assign groups = site.data.opportunities | group_by: "person" %}
<ul>
{% for g in groups %}
{% assign leads = g.items | where: "status", "lead" %}
<li>name : {{ g.name }} {{ leads.size }} leads</li>
{% endfor %}
</ul>