Finding the right function in Excel to calculate - excel

I have data like this:
A: B: C:
1: 4-jan-16 117 85
2: 11-jan-16 58 11
3: 18-jan-16 101 98
...
and so on up to 2-jan-17.
I need to calculate the difference between b1-c1, b2-c1 for each month (c1=85=Jan, c2=111=Feb, c3=98=March).
Then I need to take the difference of every week and ^2
I have no clue on how to go about it, I have looked up many function just not sure which would do the trick. Please feel free to ask for additional details...
UPDATE
outcome should be (add a column D)
A: B: C: D:
1: 4-jan-16 117 85 =b1-c1
2: 11-jan-16 58 11 =b2-c1
3: 18-jan-16 101 98 =b3-c1
4: 25-jan-16 110 10 =b4-c1
5: 1-Feb-16 52 =b5-c2
For the column B, I used the following (have 2 sheets one called BE, the other sheet1)
=AVERAGEIFS('BE'!$H$157:$H$208,'BE'!$B$157:$B$208,">="&A7,'BE'!$B$157:$B$208,"<="&EOMONTH(Sheet1!A7,0))
Was wondering if I could use something like that to calculate the difference for every week in column D

In D1 use the following and copy down.
=B1-INDEX($C$1:$C$4,MONTH(A1))
C1:C4 is the range for you month results This method will only word for the 1 year and needs your data start in January as that is month 1. The formula above also assumes your data start in row 1. If you Data does not start in row 1 then you would want to modify the formula as follows:
=B5-INDEX($C$5:$C$16,MONTH(A5)+row(A5)-(row($A$5)-1))
'This example assumes your data stated in row 5 and you had 12 month of monthly data in column C.

Related

extract values based on two columns

I would like to extract a price value based on two other columns. In table 1, I am given the raw data where I want to draw from. In Table 2, I am given only the contract number, and I would like to find the type being "Mater" and have the price listed out for it.
I've tried to use this formula but I don't think I am calling the columns correctly.
=IF(AND(Table2!A1=Table1!$A$1:$A$6,Table1$C$1:$C$6="Mater"),Table1!$D$2:$D$6,"")
Is there a formula using index match, if(and), or another one that could work in this case?
Thank you!
Table 1.
Contract
Work
Type
Cost
5321a
aaa
Labor
52
5321a
ab
Mater
57
5641a
aba
Mater
10
536451a
aae
Labor
75
2441a
aan
Labor
42
53421
aar
Mater
14
Table 2
Contract
Mater Cost
5321a
57
5641a
57
53421
14
The following should work:
=SUMIFS(Sheet1!D2:D7,Sheet1!A2:A7,A2,Sheet1!C2:C7,"Mater")
(I'm assuming the first table in on Sheet1)

Sum of the greatest value in one column, plus the sum of the other values in another column

Consider the following sheet/table:
A B
1 90 71
2 40 25
3 60 16
4 110 13
5 87 82
I want to have a general formula in cell C1 that sums the greatest value in column A (which is 110), plus the sum of the other values in column B (which are 71, 25, 16 and 82). I would appreciate if the formula wasn't an array formula (as in requiring Ctrl + Shift + Enter). I don’t have Office 365, I have Excel 2019.
My attempt
Getting the greatest value in column A is easy, we use MAX(A1:A5).
So the formula I want in cell C1 should be something like:
=MAX(A1:A5) + SUM(array_of_values_to_be_summed)
Obtaining the values of the other rows in column B (what I called array_of_values_to_be_summed in the previous formula) is the hard part. I've read about using INDEX, MATCH, their combination, and obtaining arrays by using parenthesis and equal signs, and I've tried that, without success so far.
For example, I noticed that NOT((A1:A5 = MAX(A1:A5))) yields an array/list containing ones (or TRUEs) for the relative position of the rows to be summed, and containing a zero (or FALSE) for the relative position of the row to be omitted. Maybe this is useful, I couldn't find how.
Any ideas? Thanks.
Edit 1 (solution)
I managed to obtain what I wanted. I simply multiplied the array obtained with the NOT formula, by the range B1:B5. The final formula is:
=MAX(A1:A5) + SUM(NOT((A1:A5 = MAX(A1:A5))) * B1:B5)
Edit 2 (duplicate values)
I forgot to explain what the formula should do if there are duplicates in column A. In that case, the first term of my final formula (the term that has the MAX function) would be the one whose corresponding value in column B is smallest, and the value in column B of the other duplicates would be used in the second term (the one containing the SUM function).
For example, consider the following sheet/table:
A B
1 90 71
2 110 25
3 60 16
4 110 13
5 110 82
Based on the above table, the formula should yield 110 + (71 + 25 + 16 + 82) = 304.
Just to give context, the reason I want such a formula is because I’m writing a spreadsheet that automatically calculates the electric current rating of the short-circuit protective device of the feeder of a group of electric motors in a house or building or mall, as required by the article 430.62(A) of the US National Electrical Code. Column A is the current rating of the short-circuit protective device of the branch-circuit of each motors, and column B is the full-load current of each motor.
You can use this formula
=MAX(A1:A5)
+SUM(B1:B5)
-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)
Based on #Anupam Chand's hint for max-value-duplicates there could also be min-value-duplicates in column B for corresponding max-value-duplicates in column A. :) This formula would account for that
=SUM(B1:B5)
+(MAX(A1:A5)-AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1))
*SUMPRODUCT((A1:A5=MAX(A1:A5))*(B1:B5=AGGREGATE(15,6,(B1:B5)/(A1:A5=MAX(A1:A5)),1)))
Or with #Anupam Chand's shorter and better readable and overall better style :)
=SUM(B1:B5)
+(MAX(A1:A5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
*COUNTIFS(A1:A5,MAX(A1:A5),B1:B5,MINIFS(B1:B5,A1:A5,MAX(A1:A5)))
The explanation works for bot solutions:
The SUM-part just sums the whole list.
The second line gets the max-value for column A and the corresponding min-value of column B for the max-values in column A and adds or subtracts it respectively.
The third line counts, how many times the corresponding min-value for the max-value occurs and multiplies it with the second line.
Can you try this ?
=MAX(A1:A5)+SUM(B1:B5)-MINIFS(B1:B5,A1:A5,MAX(A1:A5))
What we're doing is adding the max of A to all rows of B and then subtracting the min value of B where A is the max.
If you have Excel 365 you can use the following LET-Formula
=LET(A,A1:A5,
B,B1:B5,
MaxA,MAX(A),
MinBExclude, MINIFS(B,A,MaxA),
sumB1,SUMPRODUCT(B*(A=MaxA)*(B<>MinBExclude)),
sumB2,SUMPRODUCT(B*(A<>MaxA)),
MaxA +sumB1+sumB2
A and B are shortcuts for the two ranges
MaxA returns the max value for A (110)
MinBExclude filters the values of column B by the MaxA-value (25, 13, 82) and returns the min-value of the filtered result (13)
sumB1 returns the sum of the other MaxA values from column B (26 + 82)
sumB2 returns the sum of the values from B where value in A <> MaxA (71 + 60)
and finally the result is returned
If you don't have Excel 365 you can add helper columns for MaxA, MinBExclude, sumB1 and sumB2 and the final result

Excel automatically charting for concrete range of data

Excel masters, I need help about charting in excel. I have a table with data ("WEEK number", "date of start", "some data") and chart! the problem is: I need when I add new week data the chart should automatically update but I need to see only 53 weeks. For example: if I add week 30 I need to see data on the chart from week 30 (2018) to week 30 (2019)
Thank you for your help in advance
Week # Start Date Data
20 05-13-2018 21,866
21 05-20-2018 20,317
22 05-27-2018 18,078
23 06-03-2018 19,254
24 06-10-2018 17,990
25 06-17-2018 19,589
26 06-24-2018 22,346
27 07-01-2018 18,985
28 07-08-2018 18,482
29 07-15-2018 17,493
30 07-22-2018 21,217
31 07-29-2018 16,205
32 08-05-2018 16,534
33 08-12-2018 16,694
34 08-19-2018 18,190
35 08-26-2018 20,559
36 09-02-2018 24,503
37 09-09-2018 26,074
38 09-16-2018 24,092
39 09-23-2018 33,828
40 09-30-2018 28,979
41 10-07-2018 28,493
42 10-14-2018 30,634
43 10-21-2018 29,473
44 10-28-2018 28,202
45 11-04-2018 30,088
46 11-11-2018 36,070
47 11-18-2018 36,689
48 11-25-2018 35,509
49 12-02-2018 27,794
50 12-09-2018 27,802
51 12-16-2018 16,521
52 12-23-2018 13,786
1 12-31-2018 18,271
2 01-07-2019 27,336
3 01-14-2019 29,837
4 01-21-2019 31,464
5 01-28-2019 31,395
6 02-04-2019 31,383
7 02-11-2019 28,152
8 02-18-2019 30,795
9 02-25-2019 25,183
10 03-04-2019 28,344
11 03-11-2019 38,064
12 03-18-2019 36,815
13 03-25-2019 36,741
14 04-01-2019 35,849
15 04-08-2019 35,199
16 04-15-2019 28,407
17 04-22-2019 16,427
18 04-29-2019 29,678
19 05-06-2019 28,270
20 05-13-2019 24,046
21 05-20-2019 21,191
22 05-27-2019 21,480
23 06-03-2019 23,919
24 06-10-2019 20,532
25 06-17-2019 20,575
26 06-24-2019 19,111
27 07-01-2019 19,279
28 07-08-2019 22,265
29 07-15-2019 5,979
You can use defined names to automatically update a chart range in Excel.
You can refer to any array/range by a name in excel. There are formulas to find the specific array/range and we call them Array Formulas. One of the most common array formula is OFFSET. If you are not familiar with this formula, please google some tutorials online before continue.
In your example, let's presume Week # is in Column A, Start Date is in Column B, and Data is in Column C, and the name of the worksheet is SheetName.
In order to dynamically look up a 53-Week range in Column A, B and C using OFFSET formula, you need to find the starting point (i.e. the cell in each column corresponds to the first week of the 53-week range) .
For instance, if your latest Week # is Week #29 in Cell A63, the starting point would be Week #29 in Cell A11. One way of finding the latest week # is to find the corresponding maximum/latest date in the Start Date column, and use MATCH formula to find the row number. Such logic is translated into the following formulas:
Start Point in Column A (the Week # column) ="A"&MATCH(MAX(B:B),B:B,0)-52
Start Point in Column B (the Start Date column) ="B"&MATCH(MAX(B:B),B:B,0)-52
Start Point in Column C (the Data column) ="C"&MATCH(MAX(B:B),B:B,0)-52
Then you can find the 53-Week range in each column by referencing the relevant starting point in the OFFSET formula. Please note you need to press CSE Ctrl+Shift+Enter upon finishing entering each array formula to make it work.
For Column A (the Week # column) =OFFSET(INDIRECT("SheetName!A"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
For Column B (the Start Date column) =OFFSET(INDIRECT("SheetName!B"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
For Column C (the Data column) =OFFSET(INDIRECT("SheetName!C"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
The next step is to create three names for the above ranges. Press Ctrl+F3 to open the Name Manager in excel, and manually create the names and copy and paste the above formulas in the 'Refers to:' field.
Then you can create a chart from the existing data, and replace the hard-coded series values with the range names to make it dynamic as shown below:
Click anywhere within the chart, then you will see the Chart Design tab shown on top of the the ribbon of your excel. Go to Select Data and Edit the Data and Date value as shown below:
I have created a sample bar chart below showing the data for the most recent 53 weeks. Please note I have added 5 weeks' of new data to test the result, and I have put the Week # as the data label for the bar chart instead of the actual dollar value.
Lastly, you can refer to the following article for more clarifications.
How to use defined names to automatically update a chart range in Excel

Modification of a set of data in Excel using complex criteria

I need to heavily modify the layout of my data. My starting point is something like (I have a lot of rows, so I would like to use some formula or macro):
t1 a
t2 b
t3 c
What I'm trying to obtain is:
t1 a
t2 a
t2 b
t3 b
t3 c
Unfortunately I'm no Excel expert, so I tried with some simple IF formulas but with no success. Any idea and suggestion would be greatly appreciated!
I'm using Excel in english version.
Thanks!
UPDATE
In particular, in the first column I have time values in seconds, while in the second column I have ID of a product. For the sake of simplicity let's assume this:
time [s] ID
1 102
3 105
5 110
6 107
and what I need to get is
time [s] ID
1 102
3 102
3 105
5 105
5 110
6 110
6 107
Obviously time is always incrementing, while the IDs are random.
Assuming your data is in the A and B columns and that your first row is the "header" row (i.e. a row with just column headers), you can use the following formulas to get the desired results:
= INDEX(A:A,FLOOR((ROW()+1)/2,1)+1)
= INDEX(B:B,FLOOR((ROW())/2,1)+1)
The first formula, put in cell for example D2 and the second formula, put in cell for example E2 and then drag down as far as necessary.
See below for a working example.

Referencing the previous row in Spotfire and a value in another column

I'm trying to do something that is very simple to do in Excel, but seems very tricky in Spotfire:
Imagine you have the following table:
A
1: 10
2: 15
3: 20
... and you want to produce the following:
A B
1: 10 10
2: 15 25
3: 20 45
In other words, add the current value of A to the previous value of B. If this was Excel, the formula in cell B3 would be = A3 + B2... However, I'm not in Excel, I'm using Spotfire... :) Any thoughts?
NB: If it makes any difference to the answer at all, I will need to use the Intersect() function in conjunction with this, as there is a categorical column to factor in as well.
Hope this helps, I have considered the first column as ID
ID A B
1 10 10
2 15 25
3 20 45
If(Sum([A]) over (AllPrevious([ID])) is null,sum([A]) over ([ID]),Sum([A]) over (AllPrevious([ID])))

Resources