Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jorgett
Contributor III
Contributor III

How to use the rank argument in the Max() function when there are duplicates in the data set

Hello Everyone,

Say I have the following data set called "Data": 1, 2, 2, 2, 4, 4, 5, 6, 6, 8.

When I use Max(Data, 1) I get 8. Max(Data, 2) = 6, BUT Max(Data, 3) = 5. This makes sense, but I wanted Max(Data,3) to equal to 6 since that is the next number in the sequence and for Max(Data, 4) = 5, Max(Data, 5) = 4 and so on. If there's  no way around this, do you have any idea of how I can go through the data set from the largest value to the lowest value without ignoring the duplicate values? Doing this in script is not an option for what I am doing and rowno() does not apply either.

Please help.

Thanks,

JF

Labels (1)
  • Max()

13 Replies
marcus_sommer

I think you could get this view by creating a calculated dimension in a table like:

valueloop(1, count(total [Column A]), 1)

and adding a bit more logic to the already mentioned expression like:

rangesum(
   pick(rowno(total), $(=concat([Column A], chr(44), -[Column A]))),
   pick(count(total [Column A]) - rowno(total) + 1, $(=concat([Column A], chr(44), -[Column A]))))

Further if you want to do it with multiple fields it might be useful to replace the static field-reference of [Column A] with something like: [$(=$Field)] or maybe with an own fieldlist (loaded with a small inline-table) and selecting it with a listbox.

- Marcus

jorgett
Contributor III
Contributor III
Author

Marcus,

I noticed when I do 

rangesum(
   pick(rowno(total), $(=concat([Column A], chr(44), -[Column A]))),
   pick(count(total [Column A]) - rowno(total) + 1, $(=concat([Column A], chr(44), -[Column A]))))

, it is ignoring the middle values. The calculation is performed for every other cell, but the ones in the middle (highlighted in red in the table below). It instead gives "-" for their corresponding cell. See table below.

189
268
268
257
44-
44-
527
628
628
819

 

I am using your exact code, I copied and paste into it and that's the result it gave me. Thanks for the help.

-JF

marcus_sommer

It's strange, it shouldn't happens … especially within a rangesum() which treats non-numeric values or NULL as zero so that if there are no numeric parameter the result should be zero, too.

This means that at least one of the parameters is invalid in the given context and prevent a correct working of the entire rangesum() so that they returned NULL (the hyphen is just a replace-char for NULL).

It's difficult to say what's causing this effect … In general I would check if there are NULL's (real NULL's, empty values, spaces, any other kind of invalid values) within the field - I assume it's rather not relevant for this example but it might cause problems and/or erroneous respectively unexpected results.
This means you need to consider strategies how to handle them - this could be the replace of them per NULL variables/mapping or any other kind of replacing (for example with a string like 'Null' or ''NV' or maybe just with 0) or to exclude them from your further calculations (maybe within a set analysis).

More likely seems to be that the pick-index failed in any way - especially if there is more than a single dimension in the table and/or there are conditions applied on the dimensions and/or there are further selections within the application. In all these cases need the rowno(total) and the count() separately checked if they return the expected values. If not it could become difficult to adjust them maybe further set analysis and/or aggr() could be used - but easier would be to simplify the objects/logics.

Another thought goes to the formatting of the fieldvalues - if they are different to the default number-format and/or this has a comma as decimal-delimiter it's troublesome. Therefore I suggest to check this, too and to apply some of the following approaches:

alt(num(floor(num#(keepchar(trim([Column A]), '0123456789,.'), 'ConvertFormat')), 'OutPutFormat'), 0)

to ensure a certain format/data-type.

- Marcus

jorgett
Contributor III
Contributor III
Author

Hi Marcus,

My apologies. I checked your code again and it is working fine. I was the one who copied it incorrectly. Thank you for your help! It's greatly appreciated.

Best,

JF