Collect rows until value in a specified column changes

I have a spreadsheet with products that need to be associated to any variants that belong to the parent sku. I have a column with “type” and each row will have either “parent” or “size” in that column. I’m trying to figure out how select a parent row, and any following rows that say size. Then I can work with that data and loop back to get the next parent/size collection of data.

Information on your n8n setup

  • n8n version: 0.230.03
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system:

Hi @keliam

Welcome to the community!

Cleanest way would probably to use a bit of code to fix it.
But a no code solution should also be possible just a bit of a head scratcher on how to do it.
Do you have some sample data we can use to get you an example?

1 Like

Sure thing! Here is a quick example. I’m not familiar enough using the code node, but assumed a solution might be possible with it.

[
  {
    "sku": "123SV",
    "type": "Parent",
    "description": "main product"
  },
  {
    "sku": 1,
    "type": "Size",
    "description": "Small"
  },
  {
    "sku": 2,
    "type": "Size",
    "description": "Medium"
  },
  {
    "sku": 3,
    "type": "Size",
    "description": "Large"
  },
  {
    "sku": 4,
    "type": "Size",
    "description": "XL"
  },
  {
    "sku": "231SV",
    "type": "Parent",
    "description": "Second Main Product"
  },
  {
    "sku": 5,
    "type": "Size",
    "description": "XL Short"
  },
  {
    "sku": 6,
    "type": "Size",
    "description": "XL Tall"
  }
]

Any advice on this one?

Sorry, Don’t have time to create you an example.