Forum Discussion
Problem using "d3-array".rollup (and it spread argument) in a Power BI Custom Visual
- 6 years ago
Hi Schizzomarino ,
Sorry, but I took a shot before trying it myself. But if I change the key attribute to ...key: any[] I can get your code working.
I do realise that the typing are a bit off now, but looks like TypeScript doesn't work correctly with this type of parameter binding.
But the most important thing: it compiles!
-JP
Hi Schizzomarino,
I can help with this, however it's not clear what your expected results are from your post. Can you perhaps share what you would expect your data to look like once processed, or explain how you expect the aggregations to work? I assume you're trying to sum the value and group by name and then by date?
And just to check-off: if this data is coming from the data model to begin with, is there a reason you're not setting up the capabilities and dataViewMapping to do the grouping for you? This way, Power BI will do the computation before the data even hits your visual code and you won't need to do the computation client-side. There will obviously be reasons to do this client-side (for instance, if you're consuming external data sources other than the data model), but just wanted to confirm whether you had considered this as it's a big difference between straight-porting some d3 code into the framework, vs. leveraging the capabilities to get your data in the right shape to begin with.
Either way, let me know what your expected outcome is for the data and I'll do my best to help.
Regards,
Daniel
- Schizzomarino6 years agoAdvocate I
Hi Daniel, dm-p ,
thanks for the reply. The reasons I don't do the grouping with dataViewMapping:
- Reuse: The pbiviz libraries change so much with every new version, I prefer using d3's latest v5 version so I can reuse it in future projets while updating to the newest and best pbiviz library.
- I would like to know how to remove limitations that d3V5 encounters in Power BI.
- Many objects are needed as to animate the visual: This is only one of the many data munching processes I need to do, including ranking the data and creating before and after snapshots for animation. I fear using dataViewMapping would be a lot more complicated than 4 lines of code in d3.
- Finally, I will be using this also on standalone webpage visualisations (to embed directly with data within webpages, with no Power BI) and would much rather use the same processes within the custom visualisation.
The output I am looking for here is an array of arrays, with the deepest arrays made up of a map (the next step would be that the pairs are iterated over using d3.pairs functionality, e.g. for ([[ka, a], [kb, b]] of d3.pairs(datevalues)){...} ), so the original data, this:
[{"date":36526,"name":"Coca-Cola","category":"Beverages","value":72537},{"date": 36526,"name": "Microsoft","category": "Technology", "value":70196},...]
Should become, this:
Thanks in advance for any guidance you may be able to provide
Dan