<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">This is an instance of the "MDX is SQL" anti-pattern. Calling aggregate functions such as Count to large numbers of cells is rarely the right thing to do in MDX. It usually indicates that the writer is thinking in SQL.<div><br></div><div>Can you create a measure [Measures].[Balance Range] that has values small, medium and large. Then you can slice on it, rather than filtering.</div><div><br></div><div>But then there's a question of when you are interested in the balance. Today? Aggregated over the last month? Aggregated over all time?</div><div><br></div><div>Hope this helps. I don't have time to fully solve your problem, but hopefully I gave you some pointers, and maybe someone else on the list can help.</div><div><br></div><div>Julian</div><div><br></div><div><div><div><div>On Jun 27, 2012, at 7:46 AM, mehdi b wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hi,</div><div><br></div><div>I want to calculate histogram data for a level over a measure of a cube.I wrote the following MDX:</div><div><br></div><div style="color: rgb(0, 0, 191);">with<br>member [Measures].[Range1] as <br>'Count(Filter([CustomerID].[CustomerID].members, [Measures].[WholeBalance]&lt;10000))'<br>member [Measures].[Range2] as <br>'Count(Filter([CustomerID].[CustomerID].members, [Measures].[WholeBalance]&gt;=10000 and [Measures].[WholeBalance]&lt;100000))'<br>select<br>{[Measures].[Range1],[Measures].[Range2]} on axis(0)<br>from [CustomerBal]<br></div><div><br></div><div>The MDX calculates the result, but my CustomerID level has 2,150,354 members, and as I checked for every calculated member, Mondrian generates a SQL to find the members with the condition in Filter() and then count every found member <span style="background-color: rgb(255, 191, 128);">in memory</span> instead of using SQL count function. This results to long execution and bad performance for my reports.</div><div><br></div><div>The generated SQL for [Measures].[range1]:</div><div style="color: rgb(127, 63, 0);">SELECT <span style="background-color: rgb(255, 191, 128);">"COR_CB_CUSTOMERBAL"."MS_CUSTOMERID" </span>AS "c0"<br>FROM "BIDWH"."COR_CB_CUSTOMERBAL" "COR_CB_CUSTOMERBAL"<br>GROUP BY "COR_CB_CUSTOMERBAL"."MS_CUSTOMERID"<br>HAVING (SUM("COR_CB_CUSTOMERBAL"."MR_WHOLEBALANCE") &lt; 10000.0)<br>ORDER BY "COR_CB_CUSTOMERBAL"."MS_CUSTOMERID" ASC</div><div><br></div><div>The generated SQL for [Measures].[range2]:</div><div style="color: rgb(127, 63, 0);">SELECT <span style="background-color: rgb(255, 191, 128);">"COR_CB_CUSTOMERBAL"."MS_CUSTOMERID"</span> AS "c0"<br>FROM "BIDWH"."COR_CB_CUSTOMERBAL" "COR_CB_CUSTOMERBAL"<br>GROUP BY "COR_CB_CUSTOMERBAL"."MS_CUSTOMERID"<br>HAVING
 ((SUM("COR_CB_CUSTOMERBAL"."MR_WHOLEBALANCE") &gt;= 10000.0)<br>AND (SUM("COR_CB_CUSTOMERBAL"."MR_WHOLEBALANCE")&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt; 100000.0))<br>ORDER BY "COR_CB_CUSTOMERBAL"."MS_CUSTOMERID" ASC</div><div><br></div><div>But it would be better if generated SQL uses the SQL count function to directly count the members. <br></div><div><br></div><div>So what can I do?<br></div></div></div>_______________________________________________<br>Mondrian mailing list<br><a href="mailto:Mondrian@pentaho.org">Mondrian@pentaho.org</a><br>http://lists.pentaho.org/mailman/listinfo/mondrian<br></blockquote></div><br></div></div></body></html>