Question on Pie Charts with Aggregate Models

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I have a lot of records I need to return, so using an Aggregate Model. I'd like to load all Account records and then show a Pie Chart by Account Type. The problem I'm running into is that each Account Type is just showing 1 record instead of the aggregated total of Account Ids.



Here is the XML - should be a simple copy-and-paste as it is using all standard Salesforce fields.

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="Account" limit="" query="true" createrowifnonefound="false" datasource="salesforce" type="aggregate" sobject="Account">
            <fields>
                <field id="Id" name="countId" function="COUNT"/>
            </fields>
            <conditions/>
            <actions/>
            <groupby method="simple">
                <field id="Type" name="type"/>
            </groupby>
        </model>
    </models>
    <components>
        <skuidvis__chart model="Account" maintitle="{{Model.labelPlural}}" type="pie" uniqueid="sk-2GYr0K-85">
            <dataaxes>
                <axis id="axis1"/>
            </dataaxes>
            <categoryaxes>
                <axis id="categories" categorytype="field"/>
            </categoryaxes>
            <serieslist>
                <series valuefield="countType" splittype="field" modelId="Account" aggfunction="count" splitfield="type"/>
            </serieslist>
            <colors/>
            <legend layout="horizontal" halign="center" valign="bottom"/>
        </skuidvis__chart>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
This should be possible with an aggregate model, right? Hopefully I'm just missing something obvious.

Thanks in advance,
Andrew
Photo of Andrew N

Andrew N

  • 1,178 Points 1k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Did you try changing the aggregate function to Sum instead of Count. I think count is just counting the rows. Sum may give you what you are expecting.
Photo of Andrew N

Andrew N

  • 1,178 Points 1k badge 2x thumb
Yes! That worked Raymond. I knew I was just overlooking some small detail. For anyone else running into this that finds this post. Here is the XML that worked:
<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="Account" limit="" query="true" createrowifnonefound="false" datasource="salesforce" type="aggregate" sobject="Account">
            <fields>
                <field id="Id" name="countId" function="COUNT"/>
            </fields>
            <conditions/>
            <actions/>
            <groupby method="simple">
                <field id="Type" name="type"/>
            </groupby>
        </model>
    </models>
    <components>
        <skuidvis__chart model="Account" maintitle="{{Model.labelPlural}}" type="pie" uniqueid="sk-2GYr0K-85">
            <dataaxes>
                <axis id="axis1"/>
            </dataaxes>
            <categoryaxes>
                <axis id="categories" categorytype="field"/>
            </categoryaxes>
            <serieslist>
                <series valuefield="countId" splittype="field" modelId="Account" aggfunction="sum" splitfield="type"/>
            </serieslist>
            <colors/>
            <legend layout="horizontal" halign="center" valign="bottom"/>
        </skuidvis__chart>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
Glad I could help!