Creating functions similar to quick table calculations

There are two ranges of functions available that work in a very similar way to some of the quick options.

The first range is the RUNNING functions, including RUNNING_SUM, RUNNING_COUNT, and so on. These functions aggregate the results that are in cells in the current partition by starting with the first one and running along, updating the calculation and aggregating the results for each new cell. While the running sum is the most obvious example, and is one of the available quick calculations, it can sometimes be useful to use another running function to provide results. For instance, the RUNNING_MAX function is useful when keeping track of a record, as the function will update to the largest value up to the point of the calculation.

When creating a table calculation, it is imperative that you use an aggregation inside of the function, as the syntax checker will remind you. 

For instance, if we wanted to keep track of our record line profit, we could create Record Line Profit as RUNNING_MAX(MAX([Profit]) and add it to a view with MAX(Profit) by Year (Order Date) and Quarter (Order Date). This will show the record to date for the largest line profit ($2,939 until Q2 2011, then $4,630 until Q3 2013, and so on).

The second type of function that should be familiar is the RANK functions, including RANK, RANK_DENSE, and so on. These functions will, as their name suggests, rank the results in the cells based on a given order (either descending (the default) or ascending, as defined by the second argument of the function). Here is a quick summary of how the different functions will rank the same set of data (10, 10, 15, 20) in ascending order:

Function How 10, 10, 15, 20 are ranked in ascending order Comment
RANK 1, 1, 3, 4 Same rank (highest) for equal values
RANK_DENSE 1, 1, 2, 3 Same rank (highest) for equal values; no gap
RANK_MODIFIED 2, 2, 3, 4 Same rank (lowest) for equal values
RANK_UNIQUE 1, 2, 3, 4 Unique rank
RANK_PERCENTILE 50, 50, 75, 100 Percentile rank (% of values equal or below this)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.18.4