I have data like this in an excel sheet:
1 2 3
4 5 6
What I am trying to do is come up with a formal that will give me the total of each row, something like this =A+B+C, so I can use this formula on each row...I have plenty of rows, The above is just and example, I have this =A1+B1+C1 is there away in excel to get A1 + B1 + C1 without the row number?
Please help, this would save me lots of time.
I have looked into =ROW to get the row number, can I use the sum function with the row function?
=SUM(A=ROW():B=ROW())
I found a solution to my problem:
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))
This will work
=SUM(INDIRECT("A"&ROW()):INDIRECT("C"&ROW()))
Related
I am wondering if there is a way to do what I want more automatically, i've been doing it with good old regular copy paste but it's taking a lot of time, I need to take the horizontal data I have currently and put it vertically while keeping the first column for each rows, the first column is my "main" part number and I need to link all the other numbers starting from column B to this main part number, example below,
I sometimes have hundreds of rows and columns to do this for, here is what i'm working with
[1]: https://i.stack.imgur.com/dIyZv.png
And here's what the end result needs to look like;
[2]: https://i.stack.imgur.com/PvxGh.png
Thank you in advance!
It can be achieved either with VBA Code or with formulas. I did it with formulas and will try to show you how below.
I have one sheet with all the data, lets call it Sheet1. It looks like this:
Then, I have another sheet which returns what you want (Sheet2). It looks as follows:
Note that the first two columns are necesary for the formulas to work. The actual result is on Columns C and D.
Now, below are the formulas (or values) you would need to put in Sheet2 to make it work:
Cell A1: 0
Cell B1: 1
Cell A2: IF(B2=1,A1+1,A1)
Cell B2: IF(B1+1=$G$1,1,B1+1)
Cell C1: OFFSET(Sheet1!$A$1,A1,0)
Cell D1: OFFSET(Sheet1!$A$1,A1,B1)
Cell G1: The number of columns in the data on Sheet1
Then, just drag the formulas (not the values in A1, B1), until you have the expected result.
I would suggest you try to implement this simple example first, and then move it to your actual spreadsheet.
Let me know how it goes.
EDIT: Regarding your comment, we could do a trick to make it work for a variable number of columns.
First, lets add some variability to the number of columns in Sheet1. This is how my new Sheet1 looks like:
On Sheet2 I added a formula to count the number of columns per row. See Column F below:
Then, the trick is to change the formulas in Column B in Sheet2:
Before: Cell B2: IF(B1+1=$G$1,1,B1+1)
After: Cell B2: IF(B1+1=OFFSET($F$4,A1,0),1,B1+1)
Note: My formula to count the number of columns per row is:
Cell F4: COUNTA(Sheet1!A1:D1)
Note: Change D1 to the max column in Sheet1. Eg. M1.
Note2: You can get rid of cell G1 now.
Start with column B and everything else becomes a doddle. I only use 1 formula for column B and no more than 1 or 2 for column A (there are 3-4+ methods, no need to duplicate yourself but choose any of them to construct A).
I'm only using 1 formula to make each column. Entire job task done in a minute-5.
Column B. Do this first for all your "column B's":'
=IF(ROW(A1)=1,INDEX(A$1:T$1,INT(((ROW()-20)/20+1-ROW($A$1))/COLUMNS(A$1:T$1))+1,MOD(ROW()-20-ROW($A$1),COLUMNS(A$1:T$1))+1),INDEX(A$1:T$1,INT(((ROW()-20)/20+1-ROW($A$1))/COLUMNS(A$1:T$1))+1,MOD(ROW()-20-ROW($A$1),COLUMNS(A$1:T$1))+1))
So all you have to do is drag down. Change only the row references to refer to your 100's if different rows you need to do this for. 1 minute. Job done
for 30 columns/cells change T to AD, for 200 cells , change T to GR, etc. You can also force it to stop at number of your choice.
If you put it anywhere else, it will still work, but your going to have to jiggy with the math a bit to get it to start from the the first entry in the row ( or the specific Wherever you want). Its up to you.
It acts like a modular clock. Been using it for a few years. Ticker tape. Rolling slabs of concrete laying out for you.
here, this is what I get when I plug it into the first row of any column , referring to a 20 field length header on my sheet.
Etc... It continues forever (or for however long you want it). (and you can change the mod anytime).
The first argument you could change to whatever your requirements are , for instance , if(LEN(F8)<1, or whatever, to Start/"Set the clock."
And For any corresponding ranges (your first column for each) (** Your "Column A's" **):
=IF(LEN(H20)<1,K21,H20)
or you can use this logic. It Becomes elementary.
=IF(J21=K21,J21,J20)
Better if you use this starting from row 2 on each column A: if(and(j1=it's next door neighbour, row(it's next door neighbour cell=1)), it's self j1,.. blah blah blah blah
OR AM I MISSING THE POINT ?
Method for getting column A;
Since you already have B, A becomes a simple trivial matter. Like cell =$fixed$cell , i.e. A1=$B$1 and drag down.
simple. headache over. game over. Its all effortless.
But if you want me to elaborate more ,
method 2 for getting 1st column, column A's;
=IF(LEN(AV1)>1,IF(ROW(AV1)=1,AV1,INDIRECT("Av"&1)),"")
=IF(ROW(B1)=1,B1,INDIRECT("B"&1)) <---- drag down from row 1
Method 1 for getting 1st column;
=IF(LEN(AV1)>1,$AV$1,"") <----- drag down from row 1
Method 3, below was my favourite:
=$B$1 <---- from row1 drag down (where row1 was just = column B, cell b1, a1=b1) easy peasy .
You could always demand a further simplification of M3:
A1=if(len(b1)>1,$b$1,"") <--drag down from b2 (where b1 was already set) *probably best because only returns a value as long as column B is .otherwise returns blank.
It's like handling duplicates by formula. Similar .
there was a method 4 too. bUt its late. (Written # 02:00)
Or did I miss the point? It's easy. Imo
Im only using 2 formulas. 1 for each column you need done . do column B first, and colimn A becomes a matter of fact . A doddle.
method 1 is my new favourite.
Its late, my naighbours have pissed me off again. Pardon my fonts and writing but seriously. didnt expect this. some people need to go to jail.(my naighbours)
So in the end: 1 formula for B. 1 for A (any one of any the 4+ methods. There are more also) , plug in and scroll for all the rows you need this done for . takes you 30 seconds? 5 minutes tops for all your rows.
I need to create a dynamic sum of data chunks out of a large data set contained in a csv file (>100k rows). The data is planned to be displayed in PowerBI but I have literately no idea of the DAX coding language or VBA. So I hope I can preformat the data in excel.
The way to distinguish the data sub-sets I want to sum up is a counting row. The rows starts with every new subset from 1 but the final number >= 1 is totally ‘random’.
The first row is the countingRow the second row is the dataRow.
> 1 45
2 20
3 20
4 10 -> SUM 95
> 1 30
2 5 -> SUM 35
> 1 X -> new SUM
I think it is possible to work with the SUM, IF and OFFSET function.
My plan was to check whether a cell contains a 1 or not. Check the range between two true values minus one cell, then calculate the offset sum in the other column.
But when I thought I found the solution I realized that I have no way to bring my pointer to a new data subset.
Which function do I need to move my calculation threw the column?
Is it even possible to do an calculation of this scale in excel?
PS: I'm although thankful for a DAX or VBA tutorial which could bring me to a solution.
In the following sample data image, use the following formula in D2.
=IF(OR(A3={1,""}), SUM(INDEX(B:B, AGGREGATE(14, 6, ROW($1:2)/(A$1:A2=1), 1)):INDEX(B:B, ROW())), TEXT(,))
Fill down.
A slightly shorter formula without array type formula:
=IF(OR(A3={1,""}),SUM($B$2:B2)-SUM($C$1:C1),"")
I have googled for hours, not being able to find a solution to what I need/want. I have an Excel sheet where I want to sum the values in one column based on the criteria that either one of two columns should have a specific value in it. For instance
A B C
1 4 20 7
2 5 100 3
3 100 21 4
4 15 21 4
5 21 24 8
I want to sum the values in C given that at least one of A and B contains a value of less than or equal to 20. Let us assume that A1:A5 is named A, B1:B5 is named B, and C1:C5 is named C (for simplicity). I have tried:
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
which gives me the rows where both columns match summed twice, and
={SUMPRODUCT(C,((A<=20)*(C<=20)))}
which gives me only the rows where both columns match
So far, I have settled for the solution of adding a column D with the lowest value of A and B, but it bugs me so much that I can't do it with formulas.
Any help would be highly appreciated, so thanks in advance. All I have found when googling is the "multiple criteria for same column" problem.
Thanks. That works. Found another one that works, after I figured out that excel does not treat 1 + 1 = 1 as I learnt in discrete mathematics, but as you say, counts the both the trues. Tried instead with:
{=SUM(IF((A<=20)+(B<=20);C;0))}
But I like yours better.
Your problem that it is "summing twice" in this formula
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
is due to addition turning first TRUE plus the second TRUE into 2. It is not actually summing twice, because for any row, if only one condition is met, it would count that row only once.
The solution is to transform either the 1 or the 2 into a 1, using an IF:
={SUMPRODUCT(C,IF((A<=20)+(C<=20))>0, 1, 0)}
That way, each value in column C would only be counted at max once.
Following this site you could build up your SUMPRODUCT() formula like this:
=SUMPRODUCT(C,SIGN((A<=20)+(C<=20)))
So, instead of a nested IF() you control your or condition with the SIGN()function.
hth
If you plan to use a large set of data then it is best to use the array formula:
{=SUM(IF((A1:A5<=20)+(B1:B5<=20),C1:C5,0))}
Obviously adjust the range to suit the data set, however if the whole of each column is to form part of the formula then you can simply adjust to:
{=SUM(IF((A:A<=20)+(B:B<=20),C:C,0))}
This will perform the calculation on all rows of data within the A, B and C columns. With either example remember to press Ctrl + Shift + Enter in order to trigger the array formula (as opposed to typing the { and }).
I have a sheet with rows of data, with many columns. I am looking for help on a formula that will extract the sum of the smallest 3 numbers in a row based on the last 5 values entered. Note that not all the rows will have values for each column, so the first value found on each row will may be found in a different column.
To determine the sum of the smallest 3 I am using the formula =SUM(SMALL(B3:R3,{1,2,3})), Unfortunately, that formula is looking at the entire range. Again, I am looking for help that with a formula that will select only the last 5 values posted.
Here is simple example. The results for each line show the totals that should be determined. Again, it needs to look for the sum of the smallest 3 based on the last 5 posted (in the example below the range would be col. 1 thru 10, with col 10 having the latest postings).
Ex.
1.....2.....3......4......5.....6.....7.....8......9.....10...... Result
31.........44....51....36..........44...34....36....38.......106 (34+36+34)
35..31...44...40.....38...52..........42....37...............115 (37+38+40)
Hope this is understandable. I am looking for a formula solution vs a VBA macro solution because of my users. Thanks for any help!!
Now that you clarified the question, I have an answer for you. This is fairly ugly but it gets the job done. You might want to hide the columns with the intermediate results - or you could get adventurous and "nest" the expressions. This makes it really hard to understand / debug though. If there's a smarter way to do this I am always open to learning.
Assuming you have the data in columns A through J, starting in row 2, put the following in cell L2:P2:
=MATCH(9999, A2:J2,1)
=MATCH(9999,OFFSET($A2,0,0, 1, L2-1)) ... copy this by dragging right to the next 2 columns
=MATCH(9999,OFFSET($A2,0,0, 1, M2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, N2-1))
=MATCH(9999,OFFSET($A2,0,0, 1, O2-1))
The first line finds the last cell with data in it; the next ones find the last cell "not including the last cell", and so they work backwards. The result is a number corresponding to the columns with data. For your example, this gives
10 9 8 7 5
9 8 6 5 4
Now we want to find the sum of the smallest 3 of these: put the following equation in cell Q2:
=SUM(SMALL(INDIRECT("RC["&P2-17&"]:RC["&L2-17&"]",FALSE),{1,2,3}))
Working from the inside out:
RC["&P2-17"] results in RC[-12], which is "the cell 12 to the left of this one".
That is the first of the "last five cells with data", cell E2
RC["&L2-17"] results in RC[-7], the last cell with data in this row
FALSE use "RC" rather than "A1" indexing
INDIRECT turn string into an address (in this case a range)
SMALL find the 3 smallest values in this range
SUM and add them together.
This formula did indeed give me 106, 115 for the example you provided.
I would hide columns L through P so you only see the result (and not the intermediate stuff).
My question is about VBA excel code.
I want to maybe write a macro but i'm not very familiar with coding so I was looking for some guidance.
Basically I have an excel spreadsheet with a table with some fields but no values filled in and then I have a seperate spreadhsheet with a table of values that I'd like to get into the first spreadsheet
For Example this would be a brief breakdown of what I have:
Height: *blank cell to be populated*
length: *blank cell to be populated*
Width: *blank cell to be populated*
I want to set up a macro so that when I type 10 into the first row (note that there are two columns, one for the noun e.g "Height" and one for the actual value.), that it will look up my second worksheet with the table of values and automatically populate the field for the length and the width based on the adjacent values in the calculations table.
I hope this is making sense!
I've tried creating a new macro and writing a basic if/and function but the macro won't run. I've enable macro's but it's telling me that my code has no defined object. Because I couldn't get that running, I didn't look to much into incorporating the lookup command.
I've done some research online into basic if/and statements and they don't seem that difficult, however my table of values has 126 different rows, each one with a height. lenght and width value, so it would be 3 horizontal columns by 126 vertical rows. It seems excessive to me to have to do that many if/and statements.
I'm also finding it difficult to do a lookup of a different worksheet. This table is very big and i'd rather have it on a seperate sheet rather than put it to the far side of the first sheet and run the lookup there (it seems to messy to me)
Sorry If I haven't explained this very well. Any help is greatly appreciated!
I suggest that you do not use VBA. You can achieve this with the VLOOKUP function.
Here are some examples that I have in Sheet2.
H L W
1 2 3
5 10 12
10 11 12
15 15 15
For convenience, I define a name, myHLW, which is defined as sheet2!$a$1 to sheet2!$c$5.
In Sheet1, I type Height Width Length in a1, b1, and c1.
I type 10 in a2. I then entered this formula in b2: =VLOOKUP($A2,myHLW,2). This tells Excel to (a) look up the value in a2 (currently 10). (b) Look in the named region, myHLW. (c) Put whatever is in column 2 in the found row. Excel fills in 11 for me.
I then entered this formula in c2: =VLOOKUP($A2,myHLW,3). This tells Excel to look up the value in a2 (currently 10), using the named region, myHLW, and place whatever is in column 3 in the found row. Excel fills in 12 for me.
I copied the formulas down, entering different heights. It looks like this:
Height Length Width
10 11 12
5 10 12
1 2 3
3.14159 2 3
Note that the heights in Sheet2 must be in ascending order. Note also that for a height that is not found (3.14159), it uses the height for 1 (the largest value that was not exceeded.)
You may also add a fourth argument, for example =VLOOKUP($A2,myHLW,3,FALSE). If the fourth argument is false, Excel will require an exact match. If you had pdone this for VLOOKUP, Excel would have placed #N/A if there were no match.