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 8413013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:49:32+00:00 2026-06-10T00:49:32+00:00

I have a requirement to calculate the installed base for units with different placements/shipments

  • 0

I have a requirement to calculate the installed base for units with different placements/shipments in different countries with different “environments” over many years given a set of certain “retirement rates” assigned to each unit. The placements, curve definitions, and curve assignments are stored in different database tables (with DDL and sample data below, also on SQLFiddle.com). The formula for calculating installed base is as follows:

enter image description here
where 1990 is the first year for which we have placement data.

The problem:

Doing these calculations with datasets of 3 to 16 million rows of unit/country/environment/year placement combinations takes much more time than the target load/calculation time of 30 seconds to 1 minute.

Sql Server approach

When PIVOTed so that each year becomes its own column, I get anywhere from 100,000 t0 400,000 returned rows of raw data (placements + rates), which takes about 8-15 seconds. However, if I were to calculate this manually via SQL statement as included below, it takes at least 10 minutes.

We’ve also tried an SQL trigger solution that updated the installed base each time a placement or rate was modified, but that made database updates unreasonably slow on batch updates, and was also unreliable. I suppose this could merit more investigation if this were really the best option.

Excel-VSTO approach (so far, the fastest approach):

This data ultimately ends up in a C# VSTO powered Excel workbook where the data was calculated via a series of VLOOKUPs, but when loading 150,000 placements across 6 years by about 20 VLOOKUPs per cell (about 20 million VLOOKUPs), Excel crashes. When the VLOOKUPs are done in smaller batches and the formulas are converted into values, it doesn’t crash but it still takes much longer than one minute to calculate.

The question:

Is there some mathematical or programmatic construct that would help me to calculate this data via C# or SQL more efficiently than I’ve been doing? Brute force iteration is also too slow, so that’s not an option either.

DECLARE @Placements TABLE 
(
    UnitId int not null,
    Environment varchar(50) not null,
    Country varchar(100) not null,
    YearColumn smallint not null,
    Placement decimal(18,2) not null,
    PRIMARY KEY (UnitId, Environment, Country, YearColumn)
)


DECLARE @CurveAssignments TABLE 
(
    UnitId int not null,
    Environment varchar(50) not null,
    Country varchar(100) not null,
    YearColumn smallint not null,
    RateId int not null,
    PRIMARY KEY (UnitId, Environment, Country, YearColumn)
)

DECLARE @CurveDefinitions TABLE
(
    RateId int not null,
    YearOffset int not null,
    Rate decimal(18,2) not null,
    PRIMARY KEY (RateId, YearOffset)
)

INSERT INTO
    @Placements
    (
        UnitId,
        Country,
        YearColumn,
        Environment,
        Placement
    )
VALUES
    (
        1,
        'United States',
        1991,
        'Windows',
        100
    ),
    (
        1,
        'United States',
        1990,
        'Windows',
        100
    )

INSERT INTO
    @CurveAssignments
    (
        UnitId,
        Country,
        YearColumn,
        Environment,
        RateId
    )
VALUES
    (
        1,
        'United States',
        1991,
        'Windows',
        1
    )

INSERT INTO
    @CurveDefinitions
    (
        RateId,
        YearOffset,
        Rate
    )
VALUES
    (
        1,
        0,
        1
    ),
    (
        1,
        1,
        0.5
    )

SELECT
    P.UnitId,
    P.Country,
    P.YearColumn,
    P.Placement *
    (
        SELECT
            Rate
        FROM
            @CurveDefinitions CD
            INNER JOIN @CurveAssignments CA ON
                CD.RateId = CA.RateId
        WHERE
            CA.UnitId = P.UnitId
            AND CA.Environment = P.Environment
            AND CA.Country = P.Country
            AND CA.YearColumn = P.YearColumn - 0
            AND CD.YearOffset = 0
    )
    +
    (
        SELECT
            Placement
        FROM
            @Placements PP
        WHERE
            PP.UnitId = P.UnitId
            AND PP.Environment = P.Environment
            AND PP.Country = P.Country
            AND PP.YearColumn = P.YearColumn - 1
    )
    *
    (
        SELECT
            Rate
        FROM
            @CurveDefinitions CD
            INNER JOIN @CurveAssignments CA ON
                CD.RateId = CA.RateId
        WHERE
            CA.UnitId = P.UnitId
            AND CA.Environment = P.Environment
            AND CA.Country = P.Country
            AND CA.YearColumn = P.YearColumn
            AND CD.YearOffset = 1
    ) [Installed Base - 1993]
FROM
    @Placements P
WHERE
    P.UnitId = 1
    AND P.Country = 'United States'
    AND P.YearColumn = 1991
    AND P.Environment = 'Windows'
  • 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-06-10T00:49:34+00:00Added an answer on June 10, 2026 at 12:49 am

    Looks like this might turn out to be a case where asking the question leads to the right answer. It turns out the answer mostly lies in the query I’d given above, which was entirely inefficient. I’ve been able to get load times in the vicinity that I’m looking for by just optimizing the query as below.

    SELECT
        P.UnitId,
        P.Country,
        P.YearColumn,
        P.Environment,
        P.Placement,
        sum(IBP.Placement * FRR.Rate) InstalledBase
    FROM
        @Placements P
        INNER JOIN @Placements IBP ON
            P.UnitId = IBP.UnitId
            AND P.Country = IBP.Country
            AND P.Environment = IBP.Environment
            AND P.YearColumn >= IBP.YearColumn
        INNER JOIN @CurveAssignments RR ON
            IBP.UnitId = RR.UnitId
            AND IBP.Country = RR.Country
            AND IBP.Environment = RR.Environment
            AND IBP.YearColumn = RR.YearColumn
        INNER JOIN @CurveDefinitions FRR ON
            Rr.RateId = FRR.RateId
            AND P.YearColumn - IBP.YearColumn = FRR.YearOffset
    GROUP BY
        P.UnitId,
        P.YearColumn,
        P.Country,
        P.Environment,
        P.Placement
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a requirement where i want to calculate last Date of a given
I have requirement, wherein I have to calculate totals for cash and credit cards
I have a requirement to calculate the average of a very large set of
I have a requirement for my new app, where i have to calculate Data
I have a requirement to calculate the Moving Range of a load of data
I have a requirement to calculate summary statistics aggregated by specific custom time periods.
My SQL is rusty -- I have a simple requirement to calculate the sum
I have requirement where some times I would like to load children as well
I have requirement to disable copy/paste/cut operations on a textbox. For this purpose I
I have requirement of specifying web part connections in onet.xml. So when site is

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.