Conditional aggregation using scope assignments

Who is online?  0 guests and 1 members
Home  »  Forums   »  microsoft business intelligence   »  bi query languages (mdx, dmx)   » Conditional aggregation using scope assignments

Conditional aggregation using scope assignments

Topic RSS Feed

Posts under the topic: Conditional aggregation using scope assignments

Posted: 8/11/2012

Jedi Youngling 2  points  Jedi Youngling
  • Joined on: 3/19/2011
  • Posts: 1

Hi,

I have read in several forums (one from Dustin Ryen in bidn) that you can use scope assignments for conditional aggregation, but unfortunately I was not able to solve my problem. I got a table as demonstrated below which I need to build a cube upon with a conditional aggregation behavior over different dimensions. Dimsarfasl and Dimshobe are dimensions and Balbed and Balbes are the measures.

dimsarfast    dimshobe   balbed   balbes

      1                    1             50          0

      1                    2              0          20

      2                    1              0          30

      2                    2              0          40

      3                    1              0          20

      3                    2             60          0

What I need is when I roll up using dimshobe I simply get a sum over dimshobe members:

dimshobe   balbed   balbes

      1               50         50

      2               60         60

and when rolling up using dimsarfasl I need to get:

dimsarfasl   balbed   balbes

      1               30         0

      2                0         70

      3               40         0

the logic is when balbed>balbes then balbed=balbed-balbes else 0 and vice versa.

to do so, I have defined two new named calculation in dsv and written scope assignments as below:

scope ([Measures].[Balbednew]);
   
    scope ([DIMSARFASL].[SARFASL].members);
       this=iif([Measures].[BALBED]>[Measures].[BALBES],[Measures].[BALBED]-[Measures].[BALBES],0);
    end scope;    

    scope ([DIMSHOBE].[SHOBE].members);
       this=[Measures].[BALBED];
    end scope;    

end scope;

scope ([Measures].[Balbesnew]);
   
    scope ([DIMSARFASL].[SARFASL].members);
       this=iif([Measures].[BALBES]>[Measures].[BALBED],[Measures].[BALBES]-[Measures].[BALBED],0);
    end scope;
    
    scope ([DIMSHOBE].[SHOBE].members);
       this=[Measures].[BALBES];
    end scope;

end scope;

As you see I have defined two scopes for each new measure. The problem is that it seems like the scope assignments overrides each other for each new defined measure (balbednew, balbesnew) and both of them do not work at the same time.

what I get is :

dimsarfasl   balbed   balbes

      1               50         20

      2                0          70

      3               60         20

dimshobe   balbed   balbes

      1               50         50

      2               60         60

and when I change the order of scopes I get:

dimsarfasl   balbed   balbes

      1               30         0

      2                0         70

      3               40         0

dimshobe   balbed   balbes

      1               0          0

      2               0          0

I really appreciate it if anybody could help me on this. 

Thanks guys.


Posted: 9/28/2012

Jedi Youngling 2  points  Jedi Youngling
  • Joined on: 9/28/2012
  • Posts: 1

Great one....


Page 1 of 1 (2 items)