# requesting (continued) help to re-structure mapped data

**URL:** <https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722>\
**Category:** Help\
**Created:** [October 19, 2021, 12:14pm UTC](https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722 "2021-10-19T12:14:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [October 19, 2021, 12:14pm UTC](https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722/1 "2021-10-19T12:14:55Z")

</div>

Hi Community.

I continue to have a bit of trouble figuring out data re-structuring and am reaching out for help.

I would like to make a [Zoomable Sunburst](https://observablehq.com/@d3/zoomable-sunburst) chat showing the distribution of households across some different administrative areas. The challenge that I am having is how to access the value for `household_total` so that it is counted appropriately.

Previously, [the community helped](https://talk.observablehq.com/t/how-to-move-from-d3-group-to-a-format-that-works-for-a-sunburst-chart/3931/3) show me how to create a nesting function that returns an array from ‘rolled up’ data, and re-labels the attribute names in a manner expected of the Zoomable Sunburst:

```auto
function nest(rollup) {
  return Array.from(rollup, ([key, value]) =>
    value instanceof Map
      ? { name: key, children: nest(value) }
      : { name: key, value: value.length}
  );
}

```

However, in the case of my data, I still need to re-work the final value so that it’s interpreted as a number, rather than a name. Without this, the final count field is interpreted just a single leaf:

![value-as-name](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/c/cd4f9dc926a4184e4fa9147e4b06036af8a88d44.png)

Try as I might, I haven’t figured out this final transformation. Here’s a notebook:

> **[Flatting Mapped Data](https://observablehq.com/d/a1544c445a3fda76)**
>
> I would like to make a Zoomable Sunburst chat showing the distribution of households across some different administrative areas. Here's the raw data: Using d3.group, I can organize this information into hierarchies: The challenge that I am having is...

Any help or insights?

---

<div class="post-metadata">

**Author:** ![Evan](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/evan/32/276_2.png) [@Evan](https://talk.observablehq.com/u/Evan)\
**Post date:** [October 19, 2021, 1:23pm UTC](https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722/2 "2021-10-19T13:23:06Z")

</div>

Hi Aaron,

I’m not entirely sure what the end product is supposed to look like, but you might try d3.rollup instead of d3.group, e.g.,

```auto
households_per_settlement_grouped = d3.rollup(
  household_data,
  (v) => d3.sum(v, (e) => e.household_total),
  (d) => d.municipality,
  (d) => d.ward,
  (d) => d.settlement_name
)

```

and change the nest function to just have `value` instead of `value.length`. I am likely completely off-base on what you are trying to achieve, but I shared a notebook with you, in case that helps.

Evan

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [October 19, 2021, 1:55pm UTC](https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722/3 "2021-10-19T13:55:53Z")

</div>

Thank you Evan! This does help… I dropped the ward tier for simplicity for now (but intend to add it). Your final mapping looks right:

![image](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/8/88984170f8dd1a54a89011d1e555c31a013818c8.png)

… unfortunately I still have an error when I try to supply the output of this rollup into the sunburst chart `RuntimeError: Cannot read properties of undefined (reading 'length')`.

Essentially, I would like the final leaf in the sunburst to be `settlement_name` and its size within it’s group to be proportional according to `households_total`. (If that’s clearly stated? Maybe not 😕 )

… looks like, to use your rolled data, I simply need to find a way to re-assign the attribute names to the mapped values. I’ll keep trying!

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [October 19, 2021, 4:34pm UTC](https://talk.observablehq.com/t/requesting-continued-help-to-re-structure-mapped-data/5722/4 "2021-10-19T16:34:45Z")

</div>

Ok, I got it - AND I remembered that [I had issues on this before](https://talk.observablehq.com/t/how-to-move-from-d3-group-to-a-format-that-works-for-a-sunburst-chart/3931/4), and getting around it required [a different sunburst chart](https://observablehq.com/d/08d45f2703b4cb7f), which Mike had graciously volunteered.

Thanks @Evan - you took me over the finish line! Based on your code, here’s the final bit:

```auto
households_per_settlement_rolled = {
  const rollup = d3.rollup(
  household_data,
  (v) => d3.sum(v, (e) => e.household_total),
  (d) => d.municipality,
  (d) => d.settlement_name);
  return d3.hierarchy(rollup).sum(([, value]) => value);
}

```
