Question

IFERROR((SUMIFS('Sheet 1'!$K:$K,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0"))/(SUMIFS('Sheet 1'!$J:$J,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")),"")

I am working with the following function in Excel and need to interpret it into MS SQL. I am familiar with SQL, but extremely unfamiliar with excel. From what I understand the function is returning "" if error. otherwise it is calling SUMIF on the innermost parentheses - inside of which I am not sure what is going on, even after looking up what !, :, and $ do in Excel

Was it helpful?

Solution

SUMIFS() adds a range of cells based on one or more criteria applied to a range of cells.

First is the range of values to be summed up, then after that come pairs of criteria, first is the criteria range, then the criteria. The first one breaks down something like this:

    SUMIFS('Sheet 1'!$K:$K   -- Sum this field
            ,'Sheet 1'!$A:$A,'Sheet 2'!I$5  --When same row in A matches Sheet 2 I5
            ,'Sheet 1'!$C:$C,'Sheet 2'!$B15 --When same row in C matches Sheet 2 B, but 15 rows down.
            ,'Sheet 1'!$K:$K,"<>0")  --When the values aren't 0

That's the numerator in your formula, you can break down the 2nd SUMIF() similarly.

OTHER TIPS

Okay since I have no idea what you sheet is I can't help with the SQL but i will try and break down the function for you

#this part is for if the enclosed returns an error like #VALUE
#you can think of this as a try rescue block of sorts
#so if there is an Error then Return ""
IFERROR(
  (
   #This part is Summing All the values in Column K for multiple criteria
   #Sum all the values in Column K ref ['Sheet 1'!$K:$K]
   #Where all the values in Column A  = Value in Cell I5 ref['Sheet 1'!$A:$A,'Sheet 2'!I$5]
   #And Values in Column C = Value in Cell B15 ref [ 'Sheet 1'!$C:$C,'Sheet 2'!$B15]
   #And the Values in Column K Do not = 0 ref ['Sheet 1'!$K:$K,"<>0"]
   SUMIFS('Sheet 1'!$K:$K,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")
  #Above Number Divided By 
  )/(
   #This part is Summing All the values in Column J for multiple criteria
   #Sum all the values in Column J ref ['Sheet 1'!$J:$J]
   #Where all the values in Column A  = Value in Cell I5 ref['Sheet 1'!$A:$A,'Sheet 2'!I$5]
   #And Values in Column C = Value in Cell B15 ref [ 'Sheet 1'!$C:$C,'Sheet 2'!$B15]
   #And the Values in Column K Do not = 0 ref ['Sheet 1'!$K:$K,"<>0"]
  SUMIFS('Sheet 1'!$J:$J,'Sheet 1'!$A:$A,'Sheet 2'!I$5,'Sheet 1'!$C:$C,'Sheet 2'!$B15,'Sheet 1'!$K:$K,"<>0")
  )
,"")

Here is the definition of SUMIFS. Quick Synopsis:

*First Argument is the Rows being Summed
*Second Argument is the Criteria Being Evaulated
*Third Argument is the Expression Being Evaluated Against
*Repeat Second and Third for all additional Criterium

Hacked SQL

SELECT Sum(Sheet1.ColumnK) / Sum(Sheet2.ColumnJ)
FROM Sheet1 JOIN Sheet2 
WHERE
Sheet1.ColumnA = 10 --I Used 10 in place of Sheet2.ColumnI Row5 as this does not translate directly in SQL
AND Sheet1.ColumnC = 20 -- Same As Above Substitution for Sheet2.ColumnB Row 15
AND Sheet1.ColumnK <> 0

Hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top