FetchXML Tutotorial

Use MIN() and MAX() Functions in FetchXML

In this blog we will learn how to Use MIN() and MAX() Functions in FetchXML?

Use MIN() and MAX() Functions in FetchXML.

MIN(): The MIN() function returns the smallest value of the selected column.

MAX(): The MAX() function returns the largest value of the selected column.

MIN() Syntax

<fetch mapping="logical" aggregate="true" version="1.0">
  <entity name="entity_name">
    <attribute name="attribute_name" alias="allias_name" aggregate="min" />
  </entity>
</fetch>

MAX() Syntax

<fetch mapping="logical" aggregate="true" version="1.0">
  <entity name="entity_name">
    <attribute name="attribute_name" alias="allias_name" aggregate="max" />
  </entity>
</fetch>

MIN() Example
The following fetchxml finds the price of the cheapest product:

<fetch mapping="logical" aggregate="true" version="1.0">
  <entity name="products">
    <attribute name="price" alias="SmallestPrice" aggregate="min" />
  </entity>
</fetch>

MAX() Example
The following fetchxml finds the price of the expensive product:

<fetch mapping="logical" aggregate="true" version="1.0">
  <entity name="products">
    <attribute name="price" alias="LargestPrice" aggregate="max" />
  </entity>
</fetch>

Leave a Reply

Your email address will not be published. Required fields are marked *