How to sum data if it falls under any arbitrary number of date ranges - date

I need a single formula for summing numbers that fall within an arbitrary number of date ranges.
You can use multiple SUMIFS() for each date range and then sum the result of those SUMIFS()s within a single cell like this:
=SUMIFS(dataRange, datesRange,">="&startDate, D:D,"<="&endDate) +
SUMIFS(dataRange, datesRange,">="&startDate, D:D,"<="&endDate) +
SUMIFS(dataRange, datesRange,">="&startDate, D:D,"<="&endDate)
But this requires that I know exactly how many date ranges I'm going to have.
For my spreadsheet I won't know how many date ranges I will have, so it has to dynamically grab the dates ranges.
Sample Google Spreadsheet (currently editable, please feel free to use)

You can use SUMIF in conjunction with the SUMPRODUCT function that multiplies components in the given arrays, and returns the sum of those products.
This can be done as below:
=SUMPRODUCT(SUMIFS(E:E,D:D,">="&A4:A100,D:D,"<="&B4:B100))

Related

Look up an account then average associated values excluding zeros

On one sheet, I have account code and in the cell next to it, I need to look up the account code on the next sheet to average the cost excluding those cells that are zero in col. b from the average calculation.
The answer for London should be: £496.33 but having tried various sumifs / countifs I cannot get it to work.
You probably need COUNTIFS which -- similar to the SUMIFS you are already using -- allows to define multiple critera and ranges.
So, if the column R contains the values, you want to build the average upon, and the column H in the respective row must equal $B$28 to be included in the sum, the respective COUNTIFS looks as follows
=SUMIFS('ESL Info'!$R:$R,'ESL Info'!H:H,$B$28)/COUNTIFS('ESL Info'!$H:$H,$B$28, 'ESL Info'!$R:$R, "<>0")
ie additionally to the value in the H-column to equal B28 it also requires the value R-column (ie the actual number you are summing up) to be different from 0
You could also add the same criteria 'ESL Info'!$R:$R, "<>0" to your SUMIFS, but that isn't necessary, because a 0 doesn't provide anything to you sum, thus it doesn't matter if it's included in the sum or not ...
And depending on the Excel version you are using, you may even have the AVERAGEIFS function available, which does exactly what you want
=AVERAGEIFS('ESL Info'!$R:$R,'ESL Info'!$H:$H;$B$28,'ESL Info'!$R:$R,"<>0")

How to divide an Aggregate and Sum function

I am working in Tableau and trying to create a formula that will return me the value of each customer that walks into a store by dividing Net Sales / Traffic. When I try to combine the two separate formulas, it gives me the following error: Cannot mix aggregate and non-aggregate arguments with this function. The two functions I created that I'm trying to divide are:
SOT = (SUM([Sales Net])-SUM([Sales Gcard Net]))/SUM([Traffic Perday]) and SOT Goal
When I look at it in Tableau, it's stating that SOT is an aggregate function. How do I work around this to be able to get
SOT / SOT Goal
Aggregate variables are values that are calculated in the view, and depend on the level of aggregation in Tableau. e.g. sum(Sales) will show different values in Tableau if it’s next to a Region dimension, or if it’s next to a Category dimension.
In order to avoid the errors you can use many solutions. My favorite is indeed LOD expressions. In your view, though I do not have required sample data and therefore, I cannot try my hands on different possibilities here, I suggest that this should work-
SOT = ({SUM([Sales Net])}-{SUM([Sales Gcard Net])})/{SUM([Traffic Perday])}
Do remember that this solution will over-ride your filters and if you are using filters you have to add all those to Context.
EDIT
While trying different possibilities remember these things...
{SUM([Sales])} will sum the sales over entire data and {} i.e. curly braces wrapped around the sum function will cause to return the value as non-aggregate. In other words, this will work as LOD and if you'll add this field to view, the sum of entire sales will be shown against each row.
{FIXED [DIMENSION NAME] : sum([Sales])} will sum sales separately for each Dimension value. Fixed statement (LOD) again returns the value as non-aggregate value. if you'll add this field to view, the sum of entire sales for that dimension will be shown against each dimension.

Amazon Quicksight: is there any way to use 2 dates as X axis?

In Quicksight, I have data like this:
What I am trying to do:
I want a chart that shows the sum of amount over created_date WITH the sum of amount over resolved_date (that second part is the challenge, the first one is easy). So it is kind of using dates as an X-axis, just that they are different date fields (created_date and resolved_date). Is there a way of doing this?

Function which finds temperatures for a given month from data

I'm having some issues creating a function with the following parameters:
Ndata = extperiod(data, year, month,time)
The data is a table with 3 columns, which from left to right are:
year/month/date, time, temperature
My goal is to create a function which can extract a time and a year/month, irrespective of the date and find it's corresponding temperature.
I need to avoid using for loops
I've been advised to use floor and find, where floor(YYYYMMDD/100) = YYYY*100 + MM, which I somehow want to integrate to my function.
I've previously found a way to extract all temperatures from the data for a given day, as follows:
k = find(data(:,1)==19750101);
data(k(1):k(end),3)
I'm trying to incorporate this method, but I think that the hint "floor(YYYYMMDD/100)" throws me a of a little.
I have tried with find(data(:,1)==floor(YYYYMMDD/100)), where I would think that I'd be given all dates with a specific year and month. For example:
find( data(:,1) == floor(19660101/100) )
I thought this would give me all points in the column vector where the value is 196601. But it doesn't.
What could I try differently?
From your explanation, your want to get all temperature for a given month, no matter time and day.
So you want to find dates that are comprised in the range [YYYYMM ; YYYY{MM+1}[ or [YYYYMM ; {YYYY+1}01[ in the case of selecting December.
Recall that you store the complete date in your table. So you need to apply your operator floor to both sides of your query, not only on the query value, because no date is floor(YYYYMMDD/100)!
As a result, try the following:
find( floor(data(:,1)/100) == floor(19660101/100) )

Getting the Sum of the Contents of Rows

I have a column with dollar amounts, such as:
$1.00
$4.00
$100.00
and so on. These values are put into the column by calculating the % of another column. I want to get the sum of all the dollar amounts of that column. I cant use Sum(data) because its static data in the column. Is there a way to get the sum easily?
Thanks!
There are a couple of different ways to deal with this:
If it's the same percentage being applied to each row, sum the original column and apply the same percentage to that sum.
If the original source of the data is from a database, do the percent calculation in your Dataset's SQL query, then use the Sum function in your Tablix as usual.
If these don't apply, you'll need to give more detailed information about your problem.