Filtering dimension queries
To filter the selected elements, use the where
keyword followed by a filtering
condition. You can filter out elements based on a general condition or based on attribute
values of type string
, int
, double
and
dateTime
.
These examples demonstrate how to filter elements based on different attributes. In all the
examples the attrName
is a string variable that contains the name of the
attribute to be retrieved. The type-comparison, also called the type of the attribute, is
decided based on the type of the right side of the comparison:
Example of filtering elements by string attribute
OLAPElementList list = on connection select all from dimName where (attrName == "5");
The right side of comparison is "5" which is of type string
. Therefore,
the attribute is retrieved as a string attribute and compared alphabetically with the value
"5".
Example of filtering elements by int attribute
OLAPElementList list = on connection select all from dimName where (attrName == 5);
The right side of comparison is 5, which is of type int
. Therefore, the
attribute is retrieved as an int attribute and compared numerically with the value 5.
Example of filtering elements by bool attribute
OLAPElementList list = on connection select all from dimName where (attrName == true);
Only Boolean attribute values are supported.
Example of filtering elements in foreach iteration by their name
You can use a dimension query and filter the dimension element by two different conditions
into two separate element lists. We recommend that you move the filtering condition from the
dimension query to this foreach
statement, which is used for iterating a
list of elements:
OLAPConnection connection = OLAPCreateNamedConnection("");
string errorMessage = "";
int errorCode = 0;
string sDimension = "Product";
string nameAttribute = "NAME";
try
{
OLAPElementList list = on connection select all from sDimension order by olapname asc, nameAttribute desc;
foreach (OLAPElement e in list where (e == "ElementName"))
{
WriteLine("\t" + ToString(e));
}
}
catch (errorMessage, errorCode)
{
WriteLine("Exception: " + errorMessage);
}
OLAPDisconnect(connection);