Diagonal Sum Product If Formula

sweetmetrics

New Member
Joined
Apr 29, 2011
Messages
22
I am stumped on coming up with a dynamic formula that calculates a value based on an increasing number of "sums of products". Specifically, I need to calculate the total number of repeat users based on a "decaying' repeat rate. In other words, I need it to calculate = Sum[... +(d5*f5)+(d4*g4)+(d3*h3)]

or in equation form for you math folks like me out there:
screenshot20120831at314.png

where
n = (1, "infinity")
and
i = {1, 2, ... (n-1)}

with
"Xn" is the calculated value of repeat users for month "n" (output/result cell)
"mi" is the number of new users (in month i)
"Nn-i" is the column 'number' of the repeat rate value (%) multiplier

Here is a screenshot of the first couple rows to illustrate:

screenshot20120831at308.png



I actually have about 70 months of data (rows) and roughly the same amount of columns representing a decaying repeat rate (70 or so) and these will be increasing as time goes on so I need this formula to be dynamic (i.e. - copy it down the column of (# of repeat users)

I am using Excel for Mac 2011.

Thanks in advance for any help! :)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
You could use a UDF:

Code:
Function SM(rCol As Range, rTbl As Range) As Double
    Dim i As Long
    Dim n As Long
    
    n = rCol.Rows.Count
    
    For i = 1 To n
        SM = SM + rCol(i).Value * Intersect(rCol(i).EntireRow, rTbl.Columns(n - i + 1)).Value
    Next i
End Function

E.g.,

Code:
      --A--- --B-- -C- D -E-- -F-- -G-- -H--
  1   Repeat Month New 0  1    2    3    4  
  2     0.02         2   1.0% 3.0% 0.0% 5.0%
  3     0.06        11   0.0% 9.1% 0.0%     
  4    6.023        54   9.3% 1.9%          
  5    6.148       186   2.7%

In A2 and copy down,

Code:
=SM($C$2:$C2, $E$2:$BV2)
 
Upvote 0
You could use a UDF:

Code:
Function SM(rCol As Range, rTbl As Range) As Double
    Dim i As Long
    Dim n As Long
    
    n = rCol.Rows.Count
    
    For i = 1 To n
        SM = SM + rCol(i).Value * Intersect(rCol(i).EntireRow, rTbl.Columns(n - i + 1)).Value
    Next i
End Function

E.g.,

Code:
      --A--- --B-- -C- D -E-- -F-- -G-- -H--
  1   Repeat Month New 0  1    2    3    4  
  2     0.02         2   1.0% 3.0% 0.0% 5.0%
  3     0.06        11   0.0% 9.1% 0.0%     
  4    6.023        54   9.3% 1.9%          
  5    6.148       186   2.7%

In A2 and copy down,

Code:
=SM($C$2:$C2, $E$2:$BV2)


Wow thank you for this! Base On the code I'm seeing, this seems perfect. Unfortunately, I'm new to using UDF's and VBA so I haven't gotten this to work yet. Do you have any links or points on how to setup a UDF? I am currently just getting a NAME? error when I use the SM UDF.

Thank you! :)
 
Upvote 0
Do Alt+F11 to open the VBE, then Insert > Module, and paste the code in the window that opens.

Then do Alt+Q to return to Excel, and enter the formula as shown.
 
Upvote 0
Do Alt+F11 to open the VBE, then Insert > Module, and paste the code in the window that opens.

Then do Alt+Q to return to Excel, and enter the formula as shown.

Ah gotcha! I did not insert it as a module, I was just pasting in the VBE area for the Workbook.

This works! Thank you, very much appreciated. :)
 
Upvote 0
The one line could be simplified (and improved) to

Code:
        SM = SM + rCol(i).Value * rCol(i, n - i + 1).Value
 
Upvote 0
Hi

Shg's udf is the way to go, it's a clear and neat solution.

If for some reason you could not use vba, however, this could be a formula solution. In A2:

=SUM($B$2:B2*(INDEX($C:$C,ROWS($A$2:A2)+ROW($A$2)-1):INDEX($2:$2,ROWS($A$2:A2)+COLUMN($A$2)+1))*(ROW($A$2:A2)+TRANSPOSE(ROW($A$2:A2))=ROW($A$2)+ROW(A2)))

This in an array formula and so MUST be confirmed with CTRL+SHIFT+ENTER and not just ENTER.

Copy down.

<table border="1" cellpadding="1" style="background:#FFF; border-collapse:collapse;border-width:2px;border-color:#CCCCCC;font-family:Arial,Arial; font-size:10pt" ><tr><th style="border-width:1px;border-color:#888888;background:#9CF " > </th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >A</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >B</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >C</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >D</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >E</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" >F</th><th style="border-width:1px;border-color:#888888;background:#9CF; text-align:center" width=30 >G</th></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>1</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">Repeat</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">Month</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:left;border-width: 1px;border-color:#888888; ">New</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">1</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">2</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">3</td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>2</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0.02</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">2</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">1.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">3.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">5.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>3</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0.06</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">11</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">9.10%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">0.00%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>4</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">6.023</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">54</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">9.30%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">1.90%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>5</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">6.148</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">186</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; ">2.70%</td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;background:#9CF; text-align:center; " ><b>6</b></td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td><td style="border-width:1px;border-color:#000000; padding-left:0.5em; padding-top:0.4em; padding-right:0.5em; padding-bottom:0.25em;text-align:right;border-width: 1px;border-color:#888888; "> </td></tr><tr><td colspan=8 style="background:#9CF; padding-left:1em" > [Book1]Sheet1</td></tr></table>
 
Upvote 0
I got about 1/3 of the way into developing a formula and punted. Nicely done, PCG.
 
Upvote 0
Another one

A B C D E F G H[TABLE="width: 389"]
<colgroup><col style="width: 48pt;" width="64"> <col style="width: 53pt; mso-width-source: userset; mso-width-alt: 2560;" width="70"> <col style="width: 48pt;" span="6" width="64"> <tbody>[TR]
[TD="class: xl65, width: 64, bgcolor: transparent"]Repeat[/TD]
[TD="class: xl65, width: 70, bgcolor: transparent"]NewUsers[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent"]Month[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent"]New[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent, align: right"]0[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent, align: right"]1[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent, align: right"]2[/TD]
[TD="class: xl65, width: 64, bgcolor: transparent, align: right"]3[/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: transparent, align: right"]0,020[/TD]
[TD="class: xl65, bgcolor: transparent, align: right"]2[/TD]
[TD="class: xl68, bgcolor: transparent, align: right"]100%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]1,00%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]3,00%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]0,00%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]5,00%[/TD]
[TD="class: xl68, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: transparent, align: right"]0,060[/TD]
[TD="class: xl65, bgcolor: transparent, align: right"]11[/TD]
[TD="class: xl68, bgcolor: transparent, align: right"]100%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]0,00%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]9,10%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]0,00%[/TD]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[TD="class: xl68, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: transparent, align: right"]6,023[/TD]
[TD="class: xl65, bgcolor: transparent, align: right"]54[/TD]
[TD="class: xl68, bgcolor: transparent, align: right"]100%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]9,30%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]1,90%[/TD]
[TD="class: xl67, bgcolor: transparent"] [/TD]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[TD="class: xl68, bgcolor: transparent"] [/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: transparent, align: right"]6,148[/TD]
[TD="class: xl65, bgcolor: transparent, align: right"]186[/TD]
[TD="class: xl68, bgcolor: transparent, align: right"]100%[/TD]
[TD="class: xl67, bgcolor: transparent, align: right"]2,70%[/TD]
[TD="class: xl67, bgcolor: transparent"] [/TD]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[TD="class: xl65, bgcolor: transparent"] [/TD]
[TD="class: xl68, bgcolor: transparent"] [/TD]
[/TR]
</tbody>[/TABLE]


Formula in A2
=SUMPRODUCT($B$2:B2,N(OFFSET($D2,-(ROW(D2)-ROW($D$2:D2)),ROW(D2)-ROW($D$2:D2),1,1)))
copy down

M.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top