Ranking in MDX (handling negative numbers)

Hi,
I have a measure in my SSAS 2008  cube that returns the rank of a product based on its growth %. The MDX definition is below:
IIF(ISEMPTY([Measures].[Growth %]), NULL,
RANK([Dim Products].[Parent Products].CURRENTMEMBER, [Dim Products].[Parent Products].[Parent Products].MEMBERS, [Measures].[Growth %]))
This works fine when the growth % is positive. But when the % is negative, it returns weird results. Example:
  Growth %  |  Rank
     290 %          1
     9.71 %         5
    12.19 %        4
    -78.52%      269
   - 18.35%      267
There are only 9 products in this dimension.
Does anyone have any idea how I can tweak the MDX so that it returns a proper rank even when the growth % is negative?
Thank you in advance for your help!

The is no problem with ranking. This SSAS 2008 example proves it:
WITH MEMBER Measures.MarginRank AS
iif( IsEmpty( [Measures].[Reseller Gross Profit Margin] ), null,
Rank( [Product].[Color].CurrentMember,
-- NonEmpty(
[Product].[Color].[Color].MEMBERS,
-- [Measures].[Reseller Gross Profit Margin]),
[Measures].[Reseller Gross Profit Margin] )
SELECT
[Measures].[Reseller Gross Profit Margin], Measures.MarginRank } on 0,
Order( [Product].[Color].[Color].MEMBERS, [Measures].[Reseller Gross Profit Margin], BDESC ) on 1
FROM
[Adventure Works]
Results look like this:
Reseller Gross Profit Margin MarginRank
White 36,39% 1
NA 29,28% 2
Silver/Black 25,94% 3
Silver 6,23% 4
Black 4,17% 5
Grey (null) (null)
Multi -2,09% 7
Red -2,22% 8
Blue -3,87% 9
Yellow -9,46% 10
Now, what you need to do in order to skip blanks is apply NonEmpty() over set on rows. See 2 lines I commented and remove comments. That will give you only 9 ranks; last 4 will be shifted down by one place. I deliberately made queries withouth NON EMPTY, to show you the behavior.
Reseller Gross Profit Margin MarginRank
White 36,39% 1
NA 29,28% 2
Silver/Black 25,94% 3
Silver 6,23% 4
Black 4,17% 5
Grey (null) (null)
Multi -2,09% 6
Red -2,22% 7
Blue -3,87% 8
Yellow -9,46% 9
Why did it happen to you since you only have 9 products as you claim?
I assume you have a parent-child dimension (because of the behavior and because the name suggests so). It was my first guess, but I wanted to make a nice example and a case using Adventure Works, so that everyone can test.
You must be considering the first level only, where there are only 9 products in your hierarchy. Well, in P/C item ordinals don't run per level. They run per branches and don't reset ever (no matter the level). So, the second member in the first level might have rank i.e. 13 if there are 11 descendants under the first member in level one of P/C. 1+11below = 12 so far, so the next one is 13.
Try the same example using Employee dimension. And you'll see ranks above 200.
Again, the same solution works, so apply NonEmpty()!
Regards,
Tomislav Piasevoli
Business Intelligence Specialist
www.softpro.hr

Similar Messages

  • Logical shift negative numbers

    So, I think i have found a bug in Labview.  I am using Labview 8.5
    I have a very very simple Vi Where i want to Right shift a negative number.  For example:
    -16 >> 2 = -4
    What i get is 16380.  If I mismatch the data types.  Meaning I right shift from a 16 integar and place the result into a 8 bit integar I get -4.  
    It would appear that the function is padding with leading zeros and not ones when handling negative numbers.   
    Is this an issue that has been fixed already?  Or am i using the function incorrectly?
    Attachments:
    Logical Shift bug.vi ‏7 KB

    Gruntboy,
         What I think you're looking for is an arithmetic shift function, while the function in Labview is a logical shift.  The difference is in the leading bit of the result when they shift a number to the right.  A logical shift right pads the numbers with '0's and an arithmetic shift right pads the numbers with their copies of their most significant bit.  This is very important when dealing with signed numbers, because the most significant bit (in standard two's complement notation) denotes whether or not a number is negative. 
         The number four (4) represented in six bits would be: 000100, and in two's complement negative four (-4) would be 111100.
    A logical shift right, which pads the numbers with a '0' on the left would be:
    000100 --> 000010  (4 --> 2)
    111100 --> 011110  (-4 --> 30)
    An arithmetic shift right, which pads the numbers with whatever their most significant bit is would be: 
    000100 --> 000010  (4 --> 2)
    111100 --> 111110  (-4 --> -2) 
    I don't see  an arithmetic shift function in Labview, but you could build one by converting the number to an array of booleans and shifting to your heart's content.
    When operating on signed numbers Arithmetic shift operations tend to be more useful, but I'm sure there would be quite a bit of confusion if the unsigned number 60 ("111110") gets right shifted and becomes 127! ("111111").
    Finally, there is "one" (heh I'm so punny) special case for arithmetic shifting.  Consider how right shifting (logical and arithmetic) 8 results in 4, then 2, then 1, then 0.  What about arithmetic right shifting of -8?  The results would be -4, then -2, then -1...... then -1, then -1, then -1, etc. 
    Worthwhile resources:
    Two's compliment notation for negative binary numbers: http://en.wikipedia.org/wiki/Two's_complement
    Logical shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Logical_shift
    Arithmetic shift explanation (w/ pictures!): http://en.wikipedia.org/wiki/Arithmetic_shift
    I hope this helps!
    Hugs,
    memoryleak 
    P.S. I noticed that you mentioned you were modeling number operations of an ASIC.  This book (ISBN: 978-0534378042) was used in the Intro to Digital Logic class I took way too long ago, and I remember it hitting very hard on binary, signs and bit operations.  Looks like a used copy can be had on Amazon for less than $40 
    Message Edited by memoryleak on 10-09-2009 11:00 AM

  • Scorecard alerts not handling negative vaules?

    I have numbers that vary between -12 and 35...
    I have a scorecard, and I want the following representation;
    negative numbers to be reflected green arrow pointing upward
    zero = no icon
    positive numbers to be relfected as red arrow pointing downward
    Alert Values set as a range by value.
    I have set my alert threasholds as;
                                     From                            To
    1  Green Arrow -       Minimum                    -1
    2. No Icon          -       -1                              0
    3. No Icon          -       0                               1
    4. Red Arrow    -       1                              Maximum
    Hiowever, checking against nmy source data,  I'm getting red arrows and no icons only,  and I should have some of each.   I have tried many different variations without getting proper results.

    Hi, Michael!
    I experienced some difficulties with the Scorecard Control, too. Especially I found it not really intuitive to find and modify the relevant properties. But I think I managed to fulfill your requirements...
    Cause I still do not know how to attach files here, I uploaded a screen-shot to my therefor opened posterous page: http://t2helsinki.posterous.com/scorecard-alerts-not-handling-negative-vaules
    I hope the image/screen-shot says it all...
    Micha
    Edited by: Michael Daun on Aug 17, 2010 10:33 AM

  • Displaying negative numbers in brackets in Excel output

    Hello all.
    I have an RTF template...I tired displaying negative numbers in brackets like : (123.80) in Excel output
    But, this is working in PDF and not in Excel.
    Please let me know the way to dsiplay the numbers in brackets.

    varma wrote:
    Negative numbers in bracket
    add a conditional statement like below.
    <?if: NUMBER_TO_CHECK < 0?> <?concat('(',NUMBER_TO_CHECK,')')?><?end if?>
    <?if: NUMBER_TO_CHECK > 0?> <?NUMBER_TO_CHECK?><?end if?>
    are you using the same template for PDF and EXCEL ?
    if so, it has to be handled little differently.
    Place this line in the beginning of the rtf
    <?param@begin:_xf;''?>
    add this condition on number column for Excel output
    <?if:$_xf='excel' and NUMBER_TO_CHECK < 0?> <?concat('(',NUMBER_TO_CHECK,')')?><?end if?>
    Try the above one it should work.
    Have a Nice dayThis didnt work.
    Say that I have element named 'market'
    I placed this condiion <?param@begin:_xf;''?> at the beginningof RTF
    Replaced the number field with this condition: <?if:$_xf='excel' and market< 0?> <?concat('(',market,')')?><?end if?>
    This is giving me a blank output in place of the number.
    >

  • Is anyone having trouble using parenthesis to show negative numbers in excel after upgrading to Yosemite?

    Since upgrading to Yosemite, I can no longer reflect negative numbers with parenthesis using excel.  All of my existing spreadsheets also no longer show parenthesis, creating formatting problems.  Is anyone else experiencing this and is there a solution?

    I suggest you post your question to Microsofts own forums for their Mac software as it's their product you're having issues with
    http://answers.microsoft.com/en-us/mac

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • HT3350 what can you do when you get this warning? "Scouting Book  Collection Index" could not be handled because Numbers cannot open files in the "Numbers Document" format.

    “Scouting Book  Collection Index” could not be handled because Numbers cannot open files in the “Numbers Document” format.

    This file was created in 2002 in MSword but this had been forgotten.
    When I went to open it.... (MSword) was not a program option on my laptop. For some reason, I assumed that either Pages or Numbers wouild open the file. How the file was created was forgotten and had no file Info, but I new that it was a table of valuable information.
    The warning threw me off, because it led me to believe that it was a Numbers file. which Numbers would not open. A paradox.
    I took the file to a laptop in OSXpanther with MSoffice and it opened in MSword. Problem Solved.
    Thank you for your help.

  • How to handle imaginary numbers in Flash

    How to handle imaginary numbers in Flash ? any ideas out
    there please

    I don't know but google does:
    http://board.flashkit.com/board/showthread.php?t=723964
    Or rather someone at the end of the search seems to.
    Go about half way down that thread. Seems like something
    relevant

  • Negative numbers in export to excel

    Hi,
    We have two servers, one (X) without SP1 and the other (Y) with SP1.
    When I make export to excel in X, the negative numbers sometimes saved as @ or the actual negative number (e.g. -42), in both cases it is saved as text.
    The positive numbers are saved as numbers.
    We saw that SAP fixed it in SP1, we tried it on Y, we got that the negative numbers always show (e.g. -42), but all the numbers, positive and negative are saved as text.
    We need to see all the actual numbers(without @), and to be saved as numbers (so we can make calculations on them).
    Does anyone have any idea?
    Thanks.

    I am on SP1 and noticed that sometimes they are saved as numbers and some are texts:
    So I am not sure of any logic or what is going on.
    Maybe as a work around you could format everything to numbers so you can do the calculation?

  • Negative Numbers importing wrong

    I have a Stored Procedure on my SQL Server 6.5 DB that returns a list of decimal values (sql datatype is decimal(5,2)), of which most are Negative numbers. When the procedure is run in a SQL tool (MS Query or ISQL) the values are returned correctly. When the stored procedure is called in Java, all values (negative or positive) are showing up as zero.
    I have tried all of the following ...
    double d = rs.getDouble(1);
    Float f = rs.getFloat(1);
    Double d2 = new Double(rs.getDouble(1));
    BigDecimal b = rs.getBigDecimal(1);
    String s = rs.getString(1);The value returned by the procedure should look something like -14.75 but when using System.out.println(f.toString()); it is shown as ".00". I have even tried exporting the data out of Java into MS Excel to see if it is just something funny with the System.out.println() statement but it shows all zeros in Excel also.
    Is there anything special or a specific data type that must be used for negative numbers to read correctly in Java? I've searched the forum, tutorials and API (1.3) and haven't found anything like this.
    Any help would be greatly appreciated!!!

    So why do you say the error has something to do with negative numbers when (in your own words): "all values (negative or positive) are showing up as zero"? I don't know what your problem is, but negative numbers probably ain't it.

  • HFM 9.3 - FR Studio - can't format negative numbers with minus sign prefix?

    How can negative numbers on an account balance report be made to appear with a leading minus sign??
    This is a necessary requirement for generating an export file for loading to our new Tax software, but does not appear to be a format option.

    Have you tried going into Format Cells - Number - Negative Number Symbols - and typing a minus sign in the prefix box?

  • Fail to handle document numbering

    Dear all,
    I had a problem with  SAP 8.82 User Defined Objects  screen. While adding document  Fail to handle document numbering:.error but the documents is added because of this post transaction is not working

    Sir Here added the screen shot for your reference

  • Negative numbers in Parentheses() in Interactive Reports in Apex 4.1

    Hi,
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.
    Can anyone please help me on this?

    divya wrote:
    I want to display the negative numbers in parentheses() in all the interactive reports in my application eg: (367,432,203.07).
    I tried using the PR format "999G999G999G999G990D00PR" in my number/date format option in 'Column Definition'. But it gives the negative number '-367432203.06895' like this '<367,432,203.07>', which is not my exact requirement.
    Is there any other number format/option to get negative numbers in parentheses in my reports.No. In 4.1 the only way to do this that preserves IR sort/aggregation/calculation functionality is to manipulate the values using a Dynamic Action/JavaScript after the page is rendered. This is not really satisfactory.
    In 4.2 I think it might be possible using a lot of extra columns, HTML Expressions, and CSS.

  • Flex 2 Stacked Bars with Negative Numbers?

    Hi guys, the strangest thing: I have a client requesting
    sacked bars for bar charts/column charts however, I can't seem to
    get the negative numbers to go below a positive x-axis.
    Do these bug logs suggest I need Flex 3?
    https://bugs.adobe.com/jira/browse/FLEXDMV-921
    https://bugs.adobe.com/jira/browse/FLEXDMV-1181
    and if that's the case, how will upgrading effect my current
    project?
    Thank you.

    Great, as in another thread defined and discused, i am
    a scripter, not a programmer, but i like oaying with math.
    Daves method is easy, but what about Random( -300,1200).
    that must be a huge array to initialize.
    my function has a restriction:
    it works only, if there is a zero in the range or you'll
    never get the highest number of the range. Also it can only have a
    linear range.
    Dave can input a list like this gRandomChoises = [
    1,3,5,7,11,13,17] , what can be very usefull in some cases.
    Cheers,
    Wolfgang

  • REG: Handling Unit Numbers

    Hi All,
    Can any one tell me the process of generating the Handling Unit Numbers.
    I am basically an abapper and I need to knoe the whole process of
    1) creating a handling unit
    2) assigning the Material Numbers
    3) Generation of Handling Unit Numbers
    I would also like to know what T Codes would be used from abap point of view.
    Thanks
    Srikanth.P

    First if you want to pack packing instructions should be maintained.
    You can  create handling units and assigbning materials to HU through HU02 transaction.

Maybe you are looking for