weighted average with sumproduct and offset - excel

I would like to do the following: Calculate a weighted average based on the scenario shown in the sample screenshot. The question I would like to anser is: What is the total amount of sales generated by employee A and employee B, respectively, in a given period (here: in 2021).
Screenshot:
My Idea was to use a sumproduct formula which selects first all items with reference to employee A and, secondly, all sales of a given product. I use the ISNUMBER(FIND()) construct as wildcard (e.g. with *) does not work with SUMPRODUCT() as far as I know. However, this formula does not work properly. Any suggestions?
=SUMPRODUCT(--(Table1[item]=$J46);Table1[2021];--(ISNUMBER(FIND("Sale";TabLe1[item])));Table1[2021])

Office 365 required:
=SUMPRODUCT(FILTER(Table1[2021],LEFT(Table1[item],4)="sale"),FILTER(Table1[2021],Table1[item]=$J46))
For older Excel version you could use:
=SUMPRODUCT((Table1[2021])*--(Table1[item]=J49),.
(OFFSET(Table1[2021],1-MATCH(J49,Table1[item],0),,))*
--(LEFT(OFFSET(Table1[item],1-MATCH(J49,Table1[item],0),,),4)="sale"))
This is provided that each employee is offset the same way for each sale product.

Related

How to sum values based on two criterias

I'm trying to sum values based on two criteria: category and month (Renew).
I want to sum categories by renew month.
So, for things renewed in March, sum separately by category, but what is monthly and have the same category, must be summed too.
Example table
For example:
I have Softwares / Apps / Sites category that have different renew dates (March, April, May, June, September and also monthly).
So, I need to separate and sum values by month, but what are "monthly" have to be summed on all months.
Like this:
Softwares / Apps / Sites category
march: 26,50
april: 24,90
may: 30,60
june: 64
september: 24,90
Hope I made it clear...
I'm going crazy with that... please, help me...
For March:
=SUMPRODUCT(B2:B1000*(C2:C1000="Softwares / Apps / Sites")*(((E2:E1000="Monthly")+(E2:E1000="March"))>0))
Categories and month can be refer to cell. In the picture I can't see column, change them with real layout.
My table data is this:
Description,Price,Category,Period,Renew,Day
Netflix.Com,9,Streaming,Monthly,Monthly,5
Disney Plus,11,Streaming,Monthly,Monthly,5
Amazonprime,8,Streaming,Monthly,Monthly,5
Youtube,8,Softwares/Apps/Sites,Monthly,Monthly,5
Spotify,6,Softwares/Apps/Sites,Monthly,Monthly,5
Google,15,Work,Monthly,Monthly,5
Bank Fees,5,Bank Taxes,Monthly,Monthly,5
Internet,20,Streaming,Monthly,Monthly,5
Healthcare,20,Health,Monthly,Monthly,5
Smart Fit,35,Academy,Annual,June,10
Cellphone Plan,20,Work,Annual,June,10
Backup sw,12.5,Softwares/Apps/Sites,Annual,March,20
Office 365,50,Softwares/Apps/Sites,Annual,June,15
Truecaller,10.9,Softwares/Apps/Sites,Annual,September,10
Kasperksy,10.9,Softwares/Apps/Sites,Annual,April,10
Canva,5.7,Work,Annual,May,15
Kasperksy,10.9,Softwares/Apps/Sites,Annual,May,15
Canva,5.7,Work,Annual,May,5
(To make it easier to answer your questions, please export the data as CSV, then use four leading spaces to format the data in your question - it saves me five minutes typing in the data, and potentially making errors).
The command to use is SUMIFS. The syntax is:
SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], …)
So, if the entire table is located between A1 and F19, I could do this:
=SUMIFS($B$1:$B$19, $C$1:$C$19,"Softwares/Apps/Sites",$D$1:$D$19,"Monthly")
With my data, a total of 14.

Calculate average based on a value column (count) in a pivot table

I'm looking a way to add an extra column in a pivot table that that averages the sum of the count for the months ("Count of records" column) within a time period that is selected (currently 2016 - one month, 2017 - full year, 2018 - 5 month). Every month would have the same number based on the year average, needs to be dynamically changing when selecting different period: full year or for example 4 months. I need the column within the pivot table, so it could be used for a future pivot chart.
I can't simply use average as all my records appear only once and I use Count to aggregate those numbers ("Count of records" column).
My current data looks like this:
The final result should look like this:
I assume that it somehow can be done with the help of "calculated filed" option but I couldn't make it work now.
Greatly appreciate any help!
Using the DataModel (built in to Excel 2013 and later) you can write really cool formulas inside PivotTables called Measures that can do this kind of thing. Take the example below:
As you can see, the Cust Count & Average field gives a count of transactions by month but also gives the average of those monthly readings for the subtotal lines (i.e. the 2017 Total and 2018 Total lines) using the below DAX formula:
=AVERAGEX(SUMMARIZE(Table1,[Customer (Month)],"x",COUNTA(Table1[Customer])),[x])
That just says "Summarize this table by count of the customer field by month, call the resulting summarization field 'x', and then give me the average of that field x".
Because DAX measures are executed within the context of the PivotTable, you get the count that you want for months, and you get the average that you want for the yearly subtotals.
Hard to explain, but demonstrates that DAX can certainly do this for you.
See my answer at the following link for an example of how to add data to the DataModel and how to subsequently write measures:
Using the Excel SMALL function with filtering criteria AND ignoring zeros
I also recommend grabbing yourself a book called Supercharge Excel when you learn to write DAX by Matt Allington, and perhaps even taking his awesome online course, because it covers this kind of thing very well, and will save you significant head-scratching compared to going it alone.

How to calculate relative average cost by department in excel?

So I am trying to calculate the average cost of On-Hand goods in this example. The goal of this would be to determine the overall cost of goods by department. This would be achieved arithmetically by taking the average cost of the good and multiplying it by the number of goods on hand for that item, and then repeating for each item. I would then want to add items from the same numerical departments to get a department item cost. Is there a way to do this within a single function in excel? So far I have:
=IF($B$2:$B$17=F2,SUMPRODUCT($C$2:$C$17,$D$2:$D$17),"null")
but it is returning an invalid output.
For Cell J2, the output I would want to look for is: $74093.80
The reason I want to do this by function is because I have a spreadsheet with over 76,000 items and 19 different departments on it and need to calculate the Average Inventory Cost of each Department.
Thank you in advance!
Click here for Excel sheet
Put the test inside the SUMPRODUCT():
=SUMPRODUCT(--(B$2:$B$17=F2),$C$2:$C$17,$D$2:$D$17)

Excel Formula IF(AND #VALUE! Error

I am working on a financial model in excel. If the number of customers is between 1-10000, the cost is .20 per customer per month, 10000-100000 is .15 per customer per month, 100k and 1MIL is .10 per customer per month and > 1MIL is .08 per month per customer.
What I would like to do is create a formula where if the cell that references the number of customers at that month is within those values above, the cost per month changes depending on the number of cstomers.
This is what I have:
=IF(AND(B6>=1,B6<=10000),$Q$6), IF(AND(B6>10000,B6<=100000),$Q$7), IF(AND(B6>100000,B6<=1000000),$Q$8),IF(AND(B6>1000000),$Q$9)
Q6, Q7, Q8, Q9 are respectively: $.20, $.15, $.10, $.08
My B6 cell is the cell that is pulling over the number of customers from another sheet.
I am getting a #VALUE! Error when I use this formula. It works if I simply have:
=IF(AND(B6>=1,B6<=10000),$Q$6) which leads me to believe that my logic is wrong with all of the IF statements, and I should be using ELSEIF but I am not sure the syntax for that.
Help is appreciated!
So this is how I fixed this issue in case anyone had the same issue:
=IF(B6<=10000,$Q$6,IF(B6<=100000,$Q$7,IF(B6<1000000,$Q$7)))
By nesting the if statements with higher values excel automatically recognizes the max value for that if statement!
It seems that you are closing the IF statements too soon. Your formula repaired would look like,
=IF(AND(B6>=1,B6<=10000),$Q$6, IF(AND(B6>10000,B6<=100000), $Q$7, IF(AND(B6>100000,B6<=1000000), $Q$8, IF(AND(B6>1000000),$Q$9))))
If you start at the upper limit, you can reduce the conditions with sequential logic.
=IF(B6>1000000,$Q$9, IF(B6>100000, $Q$8, IF(B6>10000, $Q$7, IF(B6>=1,$Q$6, 0))))
You could probably do that a little more easily like this
=IF(B6>1000000,$Q$9,IF(B6>100000,$Q$8,IF(B6>10000,$Q$7,IF(B6>=1,$Q$6,"Error))))
You don't need AND because the IF functions are implicitly checking a range because the previous IFs rule out ranges of values

Calculating Percent of Total in Power Pivot Model

I have created a power pivot table as shown in the picture. I want to calculate quarter over quarter sales change. For which I have to divide for example corporate family "Acer" 's sales in 2012Q4 by sum of all the corporate family. I am using calculated measure to do this, but I am not sure what formula I can use.
My need is to create two columns, one for 2012Q4 percent of total and one for 2013Q1 percent of total. Then I will create another measure to find the difference. So the formula for 2012Q4 should be like this 1624442 / (1624442+22449+1200+16123) . Any idea which function can help me do it?
It sounds like you are measuring the change in the percent of total for each corporate family from quarter to quarter. You will need to create 3 calculated measures. I'm not sure what your model looks like so I can't give you the exact formula, but here is the idea.
CurrentQtr%ofTotal:= Divide(Sum('Sales'[Units]),Calculate(Sum('Sales'[Units]), All['Product'[Corporate Family])))
PrevQtr%ofTotal:= DIVIDE(CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER)),
CALCULATE(Sum('Sales'[Units]), DATEADD(DimDate[DateKey], -1, QUARTER), All('Product'[Corporate Family]))))
Change%ofTotal:= DIVIDE(([CurrentQtr%ofTotal]-[PrevQtr%ofTotal]),[PrevQtr%ofTotal])
I used the divide function because it handles divide by zero errors. You use the ALL function to remove the filter on the Corporate Family column from the filter context. The Change%ofTotal is just to find the differenc. I'm calculating % change but you may just want to subtract.
Here's the link to a good blog post on time intelligence. And here's one on calculating percent of total.
For percentages please follow the tutorial on the Tech on the Net.
Adding another column where you calculate a difference between two pivot columns will not work - this column is "unpivotable", as it relies on a column defintion. You would need to copy and paste pivot as values to another worksheet and do the extra calculation there.

Resources