Share via

Percent Rank ()

Anonymous
2021-11-17T16:12:04+00:00

Hi Everyone

I have a SQL Server backend for my Access development. I am trying to get Percent Rank to work with a rolling window. Consider the below example

Day Value

1 10

2 11

3 17

4 12

5 27

6 11

7 19

8 10

9 15

10 12

On Day 1, to find the percent rank of 10 look at the last 4 periods. The relevant data set is {10,11,17,12}

On Day 2, to find the percent rank of 11 look at the last 4 periods. The relevant data set is {11,17,12,27}

I want to use native SQL Server commands in order to achieve maximum efficiency.

SQL Server has a Percent Rank () function that does what I want except I just can't figure out how to get the rolling window part to work. The first thing I did was get the rolling window logic to work for a simple function like SUM. The below works because it produces the correct result:

SELECT *,

SUM(PRICES) OVER (PARTITION BY SYMBOL ORDER BY QUOTE_DATE ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS CURRENTANDPREV3

FROM DBO.Stock

This tells me that the syntax to implement the rolling window feature works (ie ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) . The next step is to replace SUM with PERCENT RANK. It doesn't work.

SELECT *,

PERCENT_RANK() OVER (PARTITION BY SYMBOL ORDER BY QUOTE_DATE ROWS BETWEEN 3 PRECEDING AND CURRENT ROW) AS CURRENTANDPREV3

FROM DBO.Stock

The error is "The function 'PERCENT_RANK' may not have a window frame"

Is there way a to implement a rolling window logic for PERCENT RANK? The database is about 4 million records (1.8 GB) so efficiency is super important.

Is anyone able to help me with this?

Thank you

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Duane Hookom 26,820 Reputation points Volunteer Moderator
    2021-11-25T05:28:23+00:00

    You are asking "to use native SQL Server commands" in a MS Access group. Consider asking in a group specifically from SQL Server.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2021-11-25T04:50:45+00:00

    is anyone able to help me with this?

    Was this answer helpful?

    0 comments No comments