简体   繁体   中英

Replacing MDX Parameters in Query String

I'm new to MDX queries and am having trouble figuring out how to use the adomd parameters correctly .The query string I'm working with is given below:

Select {
    [Measures].[Unit On Order], 
    [Measures].[Cost On Order], 
    [Measures].[Retail On Order] 
} on columns, 
NON EMPTY 
{ 
    [Product].[Universal Customer Choice Code].&[@GlobalId] 
} 
* 
{ 
    [Date].[01 - Fiscal Week].[@StartFiscalWeek] : [Date].[01 - Fiscal Week].[@EndFiscalWeek] 
} on rows 
from [Buy Plan] 
where ( 
    [Brand].[Brand].[@Brand], 
    [Market].[Market].[@Market], 
    [Reporting Currency].[Reporting Currency].&[@ReportingCurrency]
    )

I have been adding parameters as such:

 var parameter = command.CreateParameter();
 parameter.ParameterName = argument.Key;
 parameter.Value = argument.Value;
 command.Parameters.Add(parameter);

When I manually replace the @parameters, the result has values. However, I am unable to do the same using the Adomd Parameters. I've seen some people suggesting StrToSet() and StrToMember(). I'm familiar with neither, nor have I been able to figure out the difference between Set and Member.

I think all that I need is to know how to correctly format my QueryString. Thanks in advance for the help!

Since the comment was long, adding it as an answer.

However, I do have some remaining questions. Why does the parameter and StrToMember require that the whole field be used? Why can't I just have the query string look like:

[Product].[Universal Customer Choice Code].[StrToMember(@GlobalId)]

Hard to explain why, that's just the syntax! You can't use StrToMember inside a statement like that.

An alternate way to build the query would have been:

StrToMember("[Product].[Universal Customer Choice Code].[" + @GlobalId + "]")

See what happened here?

What @GlobalID passes from your report is a string value. You can concat this value to static strings and convert this to a well-formed member definition. Next step would be to just convert this string to a member by using the StrToMember function.

Do note that if you intend to add more members in future, then StrToMember function wont work anymore. You would have to use StrToSet .

Hope it helps.

Holy moly i figured it out! Probably a simple answer for those of you who know how to use MDX but maybe this'll be useful for someone else.

My first problem: My parameters were formatted incorrectly.

 var param_wrong = new AdomdParameter("@Global", 012345);

That's incorrect because the '@' should not be included in the parameter declaration, only within the Query string.

 var param_almost_correct = new AdomdParameter("Global", 012345);

My second problem: My initial query string didn't include StrToMember. I finally figured out how to use it. StrToMember should include the entire field. Now the parameter should reflect this.

 var param_correct = new AdomdParameter("Global", [Product].[Universal Customer Choice Code].[000113416000]);

The third problem and final change was creating a properly formatted query string, given below.

   Select { 
   [Measures].[Unit On Order], 
   [Measures].[Cost On Order], 
   [Measures].[Retail On Order] } 
   on columns, 
   NON EMPTY {  
      StrToMember(@GlobalId) } * 
     { StrToMember(@StartFiscalWeek) : StrToMember(@EndFiscalWeek) } 
   on rows from [Buy Plan] 
   where( 
      StrToMember(@Brand), 
      StrToMember(@Market), 
      StrToMember(@ReportingCurrency) ) 

However, I do have some remaining questions. Why does the parameter and StrToMember require that the whole field be used? Why can't I just have the query string look like:

 [Product].[Universal Customer Choice Code].[StrToMember(@GlobalId)]

I tried it like this but it did not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM