Comparing results of two MDX query using c#

5 pts.
Tags:
CELLSET COMPARISON
MDX Query

Hi, I have to run two MDX query source and target query. And compare the results and show the difference alone. I'm writing the script using C#. Here is the sample code which I'm using I'm able to retreive the cellset but not sure about compare.

int col_dim_count_source; int row_dim_count_source; int row_count_source; int col_count_source; string strText; string strToFile; decimal value; string sTmp; //============Source===================== //check if any axes were returned else throw error. int axes_count_source = cst_source.Axes.Count; if (axes_count_source == 0) throw new Exception("No data returned for the selection in Source cellset"); //if axes count is not 2 if (axes_count_source != 2) throw new Exception("Source Cellset-The sample code support only queries with two axes"); //if no position on either row or column throw error if (!(cst_source.Axes[0].Positions.Count > 0) || !(cst_source.Axes[1].Positions.Count > 0)) throw new Exception("No data returned for the selection in Source cellset"); //Number of dimensions on the column col_dim_count_source = cst_source.Axes[0].Positions[0].Members.Count; //Number of dimensions on the row row_dim_count_source = 0; if (cst_source.Axes[1].Positions[0].Members.Count > 0) row_dim_count_source = cst_source.Axes[1].Positions[0].Members.Count; //Total rows and columns = number of rows + rows for column headers row_count_source = cst_source.Axes[1].Positions.Count + col_dim_count_source; //number of columns + columns for row headers col_count_source = cst_source.Axes[0].Positions.Count + row_dim_count_source; //============End Source====================== string path = @"C:TempMDXData.csv"; StreamWriter sw = File.CreateText(path); for (int cur_row = 0; cur_row < row_count_source; cur_row++) { strToFile = ""; for (int cur_col = 0; cur_col < col_count_source; cur_col++) { //check if we are writing to a ROW having column header if (cur_row < col_dim_count_source) { //check if we are writing to a cell having row header if (cur_col < row_dim_count_source) { //this should be empty cell -- it's on top left of the grid. if (cur_col < col_count_source) strToFile = strToFile + ","; } else { //this is a column header cell -- use member caption for header strText = cst_source.Axes[0].Positions[cur_col - row_dim_count_source].Members[cur_row].Caption; strToFile = strToFile + strText; if (cur_col < col_count_source) strToFile = strToFile + ","; } } else { //Writing a row having data (not column headers) //check if we are writing to a cell having row header if (cur_col < row_dim_count_source) { //this is a row header cell -- use member caption for header strText = cst_source.Axes[1].Positions[cur_row - col_dim_count_source].Members[cur_col].Caption; strToFile = strToFile + strText; if (cur_col < col_count_source) strToFile = strToFile + ","; } else { //this is data cell.. so we write the Formatted value of the cell. strText = cst_source[cur_col - row_dim_count_source, cur_row - col_dim_count_source].FormattedValue; if (strText != "" && strText != null) { sTmp = strText.Replace("(", ""); strText = sTmp.Replace(")", ""); value = decimal.Parse(strText, CultureInfo.GetCultureInfo("en-US")); strText = value.ToString(); } else if (strText == null) strText = ""; strToFile = strToFile + strText; if (cur_col < col_count_source) strToFile = strToFile + ","; } } } //write string to file after each row sw.WriteLine(strToFile); } sw.Close(); }

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following