Understanding a Excel sumproduct formula involving exponent - excel-2007

I am trying to understand what this Excel Sumproduct formula is doing.
I read on SUMPRODUCT function, but unable to catch the role played by the exponent, minus symbol and the sequence of actions, particularly the exponent being applicable to (C3:C4-B10) as a whole.
SUMPRODUCT((C3:C4-B10)^2,D3:D4)
The function produces a valid result. It is used in the context of standard deviation.
Can anyone mention the sequence of actions taken by the formula ?

Re-writing the expression:
=(C3-B10)^2*D3+(C4-B10)^2*D4
So if A1 contains the original formula and A2 contains the re-written formula:

Related

VBA formula for cell in excel, inserting special character ambiguously [duplicate]

I am adding a formula to a worksheet via VBA which should be:
=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""))
This utilises the new SPILL feature in Excel to give me a list of column B values where the related value in column A matches what is in cell A. I'm also applying the UNIQUE function to remove any multiple blank ("") results.
This works perfectly if I manually type the formula into Excel, however in using VBA to add the formula, Excel is adding # symbols within the formula, and causing it to show #VALUE!.
The VBA line being used to add the formula is:
=Cells(x,y).Formula = "=UNIQUE(IF(TableA[ColumnA]=A1,TableA[ColumnB],""""))"
The resulting output in Excel is:
=#UNIQUE(IF(TableA[#[ColumnA]]=A1,TableA[ColumnB],""))
What is going on, and what have I missed?
Thanks in advance!
Good question, and I looked it up...
In short:
Use =Cells(x,y).Formula2 instead of =Cells(x,y).Formula
Explaination:
The # that shows is called the implicit intersection operator. From MS docs:
Implicit intersection logic reduces many values to a single value. Excel did this to force a formula to return a single value, since a
cell could only contain a single value. If your formula was returning
a single value, then implicit intersection did nothing (even though it
was technically being done in the background).
But why does it appear in your newer Excel O365? Well, Range.Formula uses IIE (implicit intersection) thus adding the # to basically undo your dynamic array functionality. UNIQUE is a new dynamic array function. So, to write this out in code, you should use the Range.Formula2 property (or Range.Formula2R1C1 if you use R1C1 notation). These properties use AE (array evaluation) and is now the default.
Here is an informative doc from MS on the subject which explains the difference between Formula and Formula2 in more detail.
If you want to know more about the implicit intersection operator then have a look at this
I answered another question earlier on that involved implicit intersection with an example on how that actually works here if one finds it interesting.

How do I prevent "format as percent" from changing the number into to a string?

Is there a way for a number to stay as a number and not a string even with the percent sign?
The reason I write a function in a query like:
Format(IIf([BDE MTOE CURRENT]=0,0,[PROJECTED OH]/[BDE MTOE CURRENT]),"Percent")
is so that I can output a complete report without having to do anything to it.
Microsoft Access (My version is 2007) changes it to a string.
You do not need to format the number in the SQL query. There is a formatting option for the values in Access reports:
If you are exporting the data to Excel there is a similar option for the Excel cells.
The bottomline is: numbers should stay numbers. That way they are better manageable: you can sort them, you can apply mathematical operations on them
Agreed. I have decided to keep numbers as decimals and will format the spreadsheet columns into percentage from MS Access using VBA. I kinda hoped I could do it all from SQL.

AutoSum and Sum return '0' when trying to add numbers imported by SQL

Excel 2007 - anytime I click AutoSum it shows 0, or anytime I use the formula to Sum it still gives me a 0.
This is a SQL Query that is imported by using Data-Connection-SQL Server and saved SQL Query in the workbook.
What gives that is keeping me from totalling?
It seems to me the most likely explanation is that what you are trying to add are strings. If so, with Error Checking activated (Formulas tab) little triangles (by default green) should be clear evidence.
These also provide an easy way to convert strings that look like numbers into numbers that Excel can add. Select a contiguous range starting with a cell requiring conversion and a warning sign should appear:
(not always top left). Click on the exclamation mark and on Convert to Number and hopefully the format of all cells in your selection will be converted so your SUM function behave as you would like.
Much less likely (because I don't see how you would have done) is that somehow you have acquired leading spaces and when entering data it was into a cell formatted as Text. The triangle warning would be the same but Number Stored as Text does no conversion. A formula such as:
=TRIM(A1)
should do however, though it does depend on the type of space (eg would not work for NBSP - though you should not acquire one of those from an SQL import).
There may be other possible causes but it seems best to try the above before alternatives.

CELL Calculation with dynamic mdx expression

I've been trying for a while to create a (little bit complicated?) cell calculation where I need to use a dynamic formula but is not working. At the end I'm obtaining the mdx expression as the cell value, which is wrong. Here is my expression:
-----------------------------------------------------------------------
---SET With 2 elements(Sales Fcst(20131223), Sales Fcst(2014))
WITH SET [CategoryFcst] AS
FILTER([Category].[Category].children, InStr([Category].[Category].CURRENTMEMBER.MEMBER_CAPTION,"Sales Fcst") > 0 )
CELL CALCULATION SalesPlanAch FOR
'([Category].[Category].[Sales Plan Att%], [Measures].[Amount])'
AS
'(StrToMember("' + [CategoryFcst].item(0).UNIQUENAME + '"),[Measures].[Amount] )'
--The formula expression result is: (StrToMember("[Category].[Category].&[29]"),[Measures].[Amount] )
SELECT [Time].[Calendar Time].[Quarter].members on columns,
[Category].[Category].children on rows
from [AllData]
WHERE ([Measures].[Amount])
-----------------------------------------------------------------------
If I put directly '(StrToMember("[Category].[Category].&[29]"),[Measures].[Amount])' as the cell calculation formula it will work, but I need to calculate that dynamically.
Also, if I put '(StrToMember("' + '[Category].[Category].&[29]' + '"),[Measures].[Amount] )' doesn't work. It sets that string as the cell value.
That is not the real cell calculation but the part that is causing me problems.
I'd appreciate any advice/answers.
Best regards,
Daniel
Just use
'(StrToMember([CategoryFcst].item(0).UNIQUENAME),[Measures].[Amount] )'
As far as I understand, the necessity of quotes around this expression is due to the history of Analysis Services as described here. And, as described in the same article, in version 2005 of Analysis Services, this was changed for member and set definitions in the WITH clause, but apparently not for the rarely used cell calculations. Hence, the quotes here are not something that encloses a string, but more or less a syntax requirement to enclose the expression.
I am actually not sure how you would use single quotes within this expression. But you can use double or single quotes in MDX expressions to enclose strings. Thus you will rarely come across the necessity to absolutely need single quotes in this type of expressions.

Excel 2007 (Conditional Formatting) AND & IF

I hope you can help me on this issue.
I am currently using Excel 2007 and I am creating a dynamic Planning/Time Sheet for our Team.
So far everything is going well.
Now unfortunately I am having an issue with the Conditional Format.
I am formatting the Cells in order to graphically show the current Status of the Person working. I am using the Conditional Format with a Formula example: =OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="PM"
Now I am trying to applying 2 conditions with a gradient fill of 2 colors like example: =AND(IF(OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="PM";TRUE;FALSE);IF(OFFSET(DataStart17D;COLUMN();ROW()-52;1;1)="AM";TRUE;FALSE)
Problem is, as soon as I use the IF or the AND Statement no condition is applied at all.
I have applied the above formula to the Cell itself and have received "TRUE" as the condition.
What is odd too is that if I apply =OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="PM" it works fine, if I use =IF(OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="PM";TRUE;FALSE) once again no condition applies.
I have searched the web for a Solution and could not find one yet :(
Would really be pleased if someone could help me on this one :)
Best Regards,
Richard J. Dana
You don't need IF Statment and TRUEs and FALSEs withih a Conditional Formatting formula. By its nature the formula is conditional.
Try something like:
=AND(OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="PM";OFFSET(DataStart17D;COLUMN();ROW()-49;1;1)="AM")
Once you do so, you'll see an additional problem. The two statements in your AND function are mutually exclusive, so it will never evaluate to TRUE.
EDIT:
There does seem to be an issue with the AND statement and multiple OFFSET statements that use ROW or COLUMN
Please note that I'm going to use commas instead of semicolons as function parameter separators here, otherwise it's too hard to convert. You'll have to change the commas back to semicolons.
Also note that you didn't need the last two arguments in either the ROW or COLUMN function in your original question. You had them set to a height and width of 1, which is the default, and is optional.
Here's a simplified example:
If you do something like:
OFFSET(DataStart17D,ROW()+1,COLUMNS())="PM"
it will evaluate to TRUE in the worksheet and also in the conditional formatting
If you do something like:
=AND(OFFSET(DataStart17D,ROW()+1,COLUMNS())="PM",OFFSET(DataStart17D,ROW()+1,COLUMNS())="PM")
which is just repeating the same statement twice, it will evaluate to TRUE in the worksheet, but won't trigger the conditional format.
All of the above is just as you stated in your question. The answer that I think works is to use ROWS and COLUMNS instead, like this:
=AND(OFFSET(DataStart17D,ROWS($1:2)+1,COLUMNS($A:A))="PM",OFFSET(DataStart17D,ROWS($1:2)+1,COLUMNS($A:A))="AM")
The above would be the formula for A2. Note that the first row or column inside the parentheses is anchored with a dollar sign. This gives you the count of rows or columns from A1, effectively the same thing as the ROW or COLUMN function.