How to calculate running total + total remaining in Excel? - excel

I have this set of data in Excel:
Date | Year | Spend | Budget | Product
Jan | 2017 | 300 | 350 | Pencils
Feb | 2017 | 450 | 450 | Pencils
March | 2017 | 510 | 520 | Pencils
... | ... | ... |
Dec | 2017 | 234 | 240 | Pencils
Jan | 2018 | 222 | 222 | Pencils
Feb | 2018 | 458 | 500 | Pencils
March | 2018 | 345 | 400 | Pencils
... | ... | ... |
Dec | 2018 | 600 | 600 | Pencils
I'm trying to build a pivot table that shows:
RT stands for "running total"
Av stands for "available"
Year | 2017
| Jan | RT | Av | Feb | RT | Av | March | RT | Av
Pencils| 300 | 300| 50 | 450 | 750| 50| 510 |1260| 60
In brief, "available" = running total + budget for remaining months. Any ideas?
Thanks!

If I understand correctly:
available = sum(budget) - sum(spent)
running total = sum(spent)
You should add a column for running total, that will sum the spent column from the beginning up to current row.
And add a column for available, that will sum the budget column from the beginning up to current row, and will reduce the value of the "running total" column (of the same row) from it.

Related

Getting the week of the year of particular days, considering Monday as the first day of the week in Excel Formula

I'm trying to find the week of the year of particular dates using a formula in Excel. I found that Excel is considering the Sunday as the 1st day of the week instead of Monday as the first day.
I used the formula =WEEKNUM(A2) (where A2 is the date row) and got the result as below
--------------------------------
| Date | Week of Year |
--------------------------------
| 5/16/2015 | 20 |
| 5/17/2015 | 21 |
| 5/18/2015 | 21 |
| 5/19/2015 | 21 |
| 5/20/2015 | 21 |
| 5/21/2015 | 21 |
| 5/22/2015 | 21 |
| 5/23/2015 | 21 |
| 5/24/2015 | 22 |
| 5/25/2015 | 22 |
--------------------------------
But how do I get the result as below (Considering Monday as the first day of the week)
--------------------------------
| Date | Week of Year |
--------------------------------
| 5/16/2015 | 20 |
| 5/17/2015 | 20 |
| 5/18/2015 | 21 |
| 5/19/2015 | 21 |
| 5/20/2015 | 21 |
| 5/21/2015 | 21 |
| 5/22/2015 | 21 |
| 5/23/2015 | 21 |
| 5/24/2015 | 21 |
| 5/25/2015 | 22 |
--------------------------------
Pass a second argument to WEEKNUM: 2 stands for Monday.
=WEEKNUM(A2, 2)

How to aggregate on a column while grouping by several columns values using CoPPer?

I have a dataset with the current stock for some products:
+--------------+-------+
| Product      | Stock |
+--------------+-------+
| chocolate    | 300 |
| coal         | 70 |
| orange juice |   400 |
+--------------+-------+
and the sales for every product over the years for the current month and the next month in another dataset:
+--------------+------+-------+-------+
| Product      | Year | Month | Sales |
+--------------+------+-------+-------+
| chocolate    | 2017 | 05 |    55 |
| chocolate    | 2017 | 04 |   250 |
| chocolate    | 2016 | 05 |    70 |
| chocolate    | 2016 | 04 |   200 |
|     |   | | |    | | | |
| coal         | 2017 | 05 |    40 |
| coal         | 2017 | 04 |    30 |
| coal         | 2016 | 05 |    50 |
| coal         | 2016 | 04 |    20 |
|     |   | | |    | | | |
| orange juice | 2017 |    05 | 400 |
| orange juice | 2017 |    04 | 350 |
| orange juice | 2016 |    05 | 400 |
| orange juice | 2016 |    04 | 300 |
+--------------+--------------+-------+
I want to compute the stock that I will need to order for the next month, by computing the expected sales over the current month and the next month, using the following formula:
ExpectedSales = max(salesMaxCurrentMonth) + max(salesMaxNextMonth)
The orders will then be
Orders = ExpectedSales * (1 + margin) - Stock
Where margin is, for example, 10%.
I tried to group by several columns using GroupBy, as in the following, but it seems to aggregate by Stock instead of Product:
salesDataset
.groupBy(Columns.col("Month"), Columns.col(“Product”))
.agg(Columns.max(“Sales”).as(“SalesMaxPerMonth”))
.agg(Columns.sum(“SalesMaxPerMonth”).as(SalesPeriod))
.withColumn(
“SalesExpected”,
Columns.col(“SalesPeriod”).multiply(Columns.literal(1 + margin)))
.withColumn(
“Orders”,
Columns.col(“SalesExpected”).minus(Columns.col(“Stock”)))
.withColumn(
“Orders”,
Columns.col(“Orders”).map((Double a) -> a >= 0 ? a: 0))
.doNotAggregateAbove()
.toCellSet()
.show();
You got the logic correct in terms of aggregation but there is another way to build your CellSet, where you provide a map to describe the location of the query which generates it.
salesDataset
.groupBy(Columns.col("Month"), Columns.col(“Product”))
.agg(Columns.max(“Sales”).as(“SalesMaxPerMonth”))
.agg(Columns.sum(“SalesMaxPerMonth”).as(SalesPeriod))
.withColumn(
“SalesExpected”,
Columns.col(“SalesPeriod”).multiply(Columns.literal(1 + margin)))
.withColumn(“Orders”, Columns.col(“SalesExpected”).minus(Columns.col(“Stock”)))
.withColumn(“Orders”, Columns.col(“Orders”).map((Double a) -> a >= 0 ? a: 0))
.doNotAggregateAbove()
.toCellSet(
Empty.<String, Object>map()
.put(“Product”,null)
.put(“Stock”, null))
.show();
Where null in a location represents the wildcard *.

Azure ML Future Prediction Algorithm

I support a business where customers pays for various services that they use on monthly basis. I would like to use machine learning based on customers' historical usage of various services and predict the future usage (increase or decrease).
I've used two class to create a model where it uses historical month-1 service usages and month-0 usage to predict the growth or decline. But I would like to start using all historical information not only m-1.
How could I do this? Is my option to keep adding (M-2,M-3,M-4) columns? if that's the case I'm going to have hundreds of columns.
I'm new to machine learning and I'm not sure which algorithm is great for the type of analysis I'm doing.
Here is an example of the original table that I have:
Customer Name | MonthName | Service | Usage
------------- | ---------------|---------|------
Customer1 | January, 2017 |Service2 |$400
Customer1 | January, 2017 |Service1 |$300
Customer1 | January, 2017 |Service3 |$0
Customer1 | December, 2017 |Service2 |$600
Customer1 | December, 2017 |Service1 |$500
Customer1 | December, 2017 |Service3 |$700
Customer1 | November, 2016 |Service1 |$500
Customer1 | November, 2016 |Service2 |$50
Customer1 | October, 2016 |Service1 |$800
Customer2 | January, 2017 |Service2 |$400
Customer2 | January, 2017 |Service1 |$800
Customer2 | December, 2017 |Service2 |$600
Customer2 | December, 2017 |Service1 |$500
Customer2 | November, 2016 |Service1 |$500
Customer2 | November, 2016 |Service2 |$50
Customer2 | October, 2016 |Service1 |$800
Here is the table I'm using right now to come up with 2 class model:
+----------------+------------------+-----------------+-----------------+-----------------+-----------+-----------+-----------+-----------+-------+--------------------+
| Customer Name | MonthName | Service1 - M-1 | Service2 - M-1 | Service3 - M-1 | Usage M-1 | Service1 | Service2 | Service3 | Usage | Usage Decline Flag |
+----------------+------------------+-----------------+-----------------+-----------------+-----------+-----------+-----------+-----------+-------+--------------------+
| Customer1 | October, 2016 | 0 | 0 | 0 | 0 | 800 | | | 800 | 0 |
| Customer1 | November, 2016 | 800 | | | 800 | 500 | 50 | | 550 | 1 |
| Customer1 | December, 2017 | 500 | 50 | | 550 | 500 | 600 | 700 | 1800 | 0 |
| Customer1 | January, 2017 | 500 | 600 | 700 | 1800 | 300 | 400 | 0 | 700 | 1 |
| Customer2 | October, 2016 | 0 | 0 | 0 | 0 | 1600 | | | 1600 | 0 |
| Customer2 | November, 2016 | 1600 | | | 1600 | 500 | 100 | | 600 | 1 |
| Customer2 | December, 2017 | 500 | 100 | | 600 | 500 | 600 | | 1100 | 0 |
| Customer2 | January, 2017 | 500 | 600 | | 1100 | 800 | 400 | | 1200 | 0 |
+----------------+------------------+-----------------+-----------------+-----------------+-----------+-----------+-----------+-----------+-------+--------------------+
try this - Here is the code that does convert rows to columns for having sales for previous days - https://gallery.cortanaintelligence.com/CustomModule/Generate-Lag-Features-1 - source code for this - https://gist.github.com/nk773/a2ed7cd0ce8020647f5e7711f749b3b5

Using a pivot table's calculated field to sum up conditional values

I have the following data set:
+--------+---------+----------+
| Date | Revenue | Expected |
+--------+---------+----------+
| Dez 5 | 51 | 1 |
| Dez 4 | 72 | 1 |
| Dez 3 | 72 | 1 |
| Dez 2 | 59 | 1 |
| Dez 1 | 81 | 1 |
| Nov 30 | 50 | 1 |
| Nov 29 | 53 | 1 |
| Nov 28 | 99 | 0 |
| Nov 27 | 85 | 0 |
| Nov 26 | 65 | 0 |
| Nov 25 | 94 | 0 |
+--------+---------+----------+
The column Expected determines whether or not the Revenue number has been confirmed. Now, I want to have a pivot table that sums up the revenues per month. The final result should be this:
+-------+-------------------+-----+
| Month | | |
+-------+-------------------+-----+
| Nov | Revenues | 446 |
| | Expected Revenues | 103 |
| Dez | Revenues | 335 |
| | Expected Revenues | 335 |
+-------+-------------------+-----+
I can't seem to get this working for the month November, because my calculated field looks like this:
=IF(Expected*1>0;Revenues*1;0)
I had to add *1 because it wouldn't work for some numbers, so you can mentally ignore this for the moment.
In any case, the result of this is the following:
+-------+-------------------+-----+
| Month | | |
+-------+-------------------+-----+
| Nov | Revenues | 446 |
| | Expected Revenues | 446 |
| Dez | Revenues | 335 |
| | Expected Revenues | 335 |
+-------+-------------------+-----+
Can anyone point me in the right direction here? I understand that the reason for this is most likely that the Expected column gets summed up first and then the IF comparison comes about. Is there a way to circumvent this?

Excel add serial number column based on another column grouped

We have thousands of rows of data in the following format
| Name | Born On |
|:-----------|------------:|
| Tom | Jul 15 |
| Harry | Jul 15 |
| Katy | Oct 2 |
| Britney | Oct 2 |
| Miranda | Oct 2 |
| Victoria | Oct 2 |
| John | Sep 30 |
| Warren | Sep 30 |
| George | Sep 30 |
I would like to add a serial number based on the "Born On" column as follows
| Name | Born On | Serial Number
|:-----------|------------:|--------------:|
| Tom | Jul 15 | 1
| Harry | Jul 15 | 2
| Katy | Oct 2 | 1
| Britney | Oct 2 | 2
| Miranda | Oct 2 | 3
| Victoria | Oct 2 | 4
| John | Sep 30 | 1
| Warren | Sep 30 | 2
| George | Sep 30 | 3
The "serial number" needs to be grouped by "born on" date.
Please help. Thanks.
If the serial numbers start in cell C2 and the Born on cells start in B2, then use this formula in cell C2 and copy down:
=COUNTIF(B$2:B2,B2)

Resources