Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6094719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:42:45+00:00 2026-05-23T12:42:45+00:00

I’ve got a table with a tracking of a plant’s equipment installation. Here is

  • 0

I’ve got a table with a tracking of a plant’s equipment installation.
Here is a sample:

ID  Name    Date    Percentage
1   GT-001  2011-01-08  30
2   GT-002  2011-01-11  40
3   GT-003  2011-02-02  30
4   GT-001  2011-02-03  50
5   GT-003  2011-02-15  50
6   GT-004  2011-02-15  30
7   GT-002  2011-02-15  60
8   GT-001  2011-02-20  60
9   GT-003  2011-03-01  60
10  GT-004  2011-03-05  50
11  GT-001  2011-03-10  70
12  GT-004  2011-03-15  60

And the corresponding script:

CREATE TABLE [dbo].[SampleTable](
[ID] [int] NOT NULL,
[Name] [nvarchar](50) NULL,
[Date] [date] NULL,
[Percentage] [int] NULL) ON [PRIMARY]
GO
--Populate the table with values
INSERT INTO [dbo].[SampleTable] VALUES
('1', 'GT-001', '2011-01-08', '30'), 
('2', 'GT-002', '2011-01-11', '40'), 
('3', 'GT-003', '2011-02-02', '30'), 
('4', 'GT-001', '2011-02-03', '50'), 
('5', 'GT-003', '2011-02-15', '50'), 
('6', 'GT-004', '2011-02-15', '30'), 
('7', 'GT-002', '2011-02-15', '60'), 
('8', 'GT-001', '2011-02-20', '60'), 
('9', 'GT-003', '2011-03-01', '60'), 
('10', 'GT-004', '2011-03-05', '50'), 
('11', 'GT-001', '2011-03-10', '70'), 
('12', 'GT-004', '2011-03-15', '60');
GO

What i need is to create a chart with Date on the X and Average Percentage on the Y. Average Percentage is an average percentage of all equipment by that particular date starting from the beggining of the installation process (MIN(Fields!Date.Value, “EquipmentDataset”))

Having no luck in implementing this using SSRS only, i decided to create a more complicated dataset for it using T-SQL.

I guess that it is nessesary to add a calculated column named ‘AveragePercentage’ that should store an average percentage on that date, calculating only the most latest equipment percentage values in a range between the beggining of the installation process (MIN(Date)) and the current row’s date. Smells like a recursion, but i’m newbie to T-SQL….))

Here is the desired output

ID  Name    Date    Percentage Average
1   GT-001  2011-01-08  30  30
2   GT-002  2011-01-11  40  35
3   GT-003  2011-02-02  30  33
4   GT-001  2011-02-03  50  40
5   GT-003  2011-02-15  50  48
6   GT-004  2011-02-15  30  48
7   GT-002  2011-02-15  60  48
8   GT-001  2011-02-20  60  50
9   GT-003  2011-03-01  60  53
10  GT-004  2011-03-05  50  58
11  GT-001  2011-03-10  70  60
12  GT-004  2011-03-15  60  63

What do you think?

I’ll be very appreciated for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:42:45+00:00Added an answer on May 23, 2026 at 12:42 pm

    You could use cross apply with row_number to find the latest value for each machine. An additional subquery is required because you cannot use row_number in the where clause directly. Here’s the query:

    select  t1.id
    ,       t1.Name
    ,       t1.Date
    ,       t1.Percentage
    ,       avg(1.0*last_per_machine.percentage)
    from    SampleTable t1
    outer apply
            (
            select  *
            from    (
                    select  row_number() over (partition by Name order by id desc)
                              as rn
                    ,       *
                    from    SampleTable t2
                    where   t2.date <= t1.date
                    ) as numbered
            where   rn = 1
            ) as last_per_machine
    group by
            t1.id
    ,       t1.Name
    ,       t1.Date
    ,       t1.Percentage
    

    Working example on SE Data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.