title: How Do I Make A Chart in Dynamics CRM that Groups by A Related Entity's Attribute?
body: <p>How can I groupby an attribute of another entity in xml charts?
  I would like a chart of number appointments (y-axis) by CRM user (x-axis), with appointments grouped by accountcategorycode of account.
  I am using a view that only displays appointments regarding accounts.</p>
  
  <p>I have a chart to group appointments by account, which works well:</p>
  
  <pre><code>    &lt;visualization&gt;
        &lt;visualizationid&gt;{8CC67476-302B-E211-86B2-005056BD0001}&lt;/visualizationid&gt;
        &lt;name&gt;Appointment by User Stacked by Rating&lt;/name&gt;
        &lt;primaryentitytypecode&gt;appointment&lt;/primaryentitytypecode&gt;
        &lt;datadescription&gt;
          &lt;datadefinition&gt;
            &lt;fetchcollection&gt;
              &lt;fetch mapping="logical" aggregate="true"&gt;
                &lt;entity name="appointment"&gt;
                  &lt;attribute groupby="true" alias="ownerid" name="ownerid" /&gt;
                  &lt;attribute groupby="true" alias="gp" name="regardingobjectid" /&gt;
                  &lt;attribute alias="accountref" name="regardingobjectid"          aggregate="count" /&gt;
                  &lt;link-entity name="account" from="accountid" to="regardingobjectid" alias="aa"&gt;
                      &lt;attribute name="accountcategorycode" alias="code" aggregate="count" /&gt;
                  &lt;/link-entity&gt;
                   &lt;filter type="and"&gt;
                      &lt;condition attribute="activitytypecode" operator="eq" value="4201" /&gt;
                  &lt;/filter&gt;
                &lt;/entity&gt;
              &lt;/fetch&gt;
            &lt;/fetchcollection&gt;
            &lt;categorycollection&gt;
              &lt;category alias="ownerid"&gt;
                &lt;measurecollection&gt;
                  &lt;measure alias="accountref" /&gt;
                &lt;/measurecollection&gt;
              &lt;/category&gt;
            &lt;/categorycollection&gt;
          &lt;/datadefinition&gt;
        &lt;/datadescription&gt;
        &lt;presentationdescription&gt;
          &lt;Chart Palette="None" PaletteCustomColors="55,118,193; 197,56,52; 149,189,66; 117,82,160; 49,171,204; 255,136,35; 97,142,206; 209,98,96; 168,203,104; 142,116,178; 93,186,215; 255,155,83"&gt;
            &lt;Series&gt;
              &lt;Series ChartType="StackedColumn" IsValueShownAsLabel="False" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40"&gt;&lt;/Series&gt;
            &lt;/Series&gt;
            &lt;ChartAreas&gt;
              &lt;ChartArea BorderColor="White" BorderDashStyle="Solid"&gt;
                &lt;AxisY LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount"&gt;
                  &lt;MajorGrid LineColor="239, 242, 246" /&gt;
                  &lt;MajorTickMark LineColor="165, 172, 181" /&gt;
                  &lt;LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" /&gt;
                &lt;/AxisY&gt;
                &lt;AxisX LabelAutoFitMinFontSize="8" TitleForeColor="59, 59, 59" TitleFont="{0}, 10.5px" LineColor="165, 172, 181" IntervalAutoMode="VariableCount"&gt;
                  &lt;MajorTickMark LineColor="165, 172, 181" /&gt;
                  &lt;MajorGrid LineColor="Transparent" /&gt;
                  &lt;LabelStyle Font="{0}, 10.5px" ForeColor="59, 59, 59" /&gt;
                &lt;/AxisX&gt;
              &lt;/ChartArea&gt;
            &lt;/ChartAreas&gt;
            &lt;Titles&gt;
              &lt;Title Alignment="TopLeft" DockingOffset="-3" Font="{0}, 13px" ForeColor="59, 59, 59"&gt;&lt;/Title&gt;
            &lt;/Titles&gt;
          &lt;/Chart&gt;
        &lt;/presentationdescription&gt;
        &lt;isdefault&gt;false&lt;/isdefault&gt;
      &lt;/visualization&gt;&lt;/visualization&gt;
  </code></pre>