Changing the column and rows in excel - excel

I have 3 columns and multiple rows and the structure of the columns/rows needs some changes. Since there is alot of rows i would want to do it with a formula or other to achieve the results and not manually change it.
Original:
Currency
Date
Value
EUR
2022-05-30
0.93
DKK
2022-05-30
1.93
SEK
2022-05-30
2.92
EUR
2022-05-31
0.95
DKK
2022-05-31
1.93
SEK
2022-05-31
2.93
EUR
2022-06-01
0.98
DKK
2022-06-01
1.93
SEK
2022-06-01
2.95
Expected:
Date
EUR
DKK
SEK
2022-05-30
0.93
1.93
2.93
2022-05-31
0.95
1.93
2.92
2022-06-01
0.98
1.93
2.95
So for each line there is originally a currency with a date and value. For each currency there is a new row (with same date). What i need is one date-row with multiple currency in one row (make currencies a column instead of rows)
I tried the Transponer in excel but it did not get me the result i wanted. This is what Transponer got me:
DKK
EUR
SEK
2022-05-30
2022-05-30
2022-05-30
1.93
0.93
2.93

The easiest way to achieve your aim, is to use a PivotTable.
To do it only using formulas.
In Excel for O365.
Extract a unique list of dates by using the UNIQUE function for the date column.
=SORT(UNIQUE(B2:B10))
Extract a unique list of currencies by using the UNIQUE function and then transpose it with the TRANSPOSE function to populate the column headings for the currencies.
=TRANSPOSE(UNIQUE(A2:A10))
Then use XLOOKUP with multiple criteria and ranges to return the matching exchange rates.
The ampersand & symbol is used to join the lookup_value and lookup_array allowing multiple criteria.
=XLOOKUP(G$1&$F2,$A$2:$A$10&$B$2:$B$10,$C$2:$C$10,0)

Related

Matrix calculations using Excel INDIRECT

I would like to run a regression in excel using LINEST function combined with INDIRECT. I need to select the time series between dates and multiply Y and X with an Index before I run the regression.
Date | Y | X | Index
30/06/1990 1.21 2.20 -
30/09/1990 0.73 1.33 -
31/12/1990 -0.07 1.31 -
31/03/1991 1.64 0.80 1.00
30/06/1991 -0.14 0.61 1.00
30/09/1991 4.13 2.37 1.00
31/12/1991 0.71 0.78 1.00
31/03/1992 0.95 0.78 -
30/06/1992 1.61 0.78 -
By using the above data, I need to use the LINEST function from 31/03/1991 until 30/06/1992 but for dates only when the index is 1.
My idea was to use INDIRECT to specify the date range, multiply the LINEST( INDIRECT(Y)*INDIRECT(Index),INDIRECT(X)*INDIRECT(Index),0,0) but I have a error.
Thank you for your help
If the cells in the target range will always be consecutive, try...
H2, confirmed with CONTROL+SHIFT+ENTER:
=SMALL(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($A$2:$A$10)))),1)
I2, confirmed with CONTROL+SHIFT+ENTER:
=LARGE(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($A$2:$A$10)))),1)
J2, confirmed with just ENTER:
=LINEST(INDEX($B:$B,H2):INDEX($B:$B,I2),INDEX($C:$C,H2):INDEX($C:$C,I2),0,0)
Otherwise, try the following instead...
H2, confirmed with CONTROL+SHIFT+ENTER:
=LINEST(N(OFFSET($B$2:$B$10,SMALL(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($B$2:$B$10)-ROW($B$2)))),ROW(INDIRECT("1:"&SUM(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,1))))))),0,1)),N(OFFSET($C$2:$C$10,SMALL(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($C$2:$C$10)-ROW($C$2)))),ROW(INDIRECT("1:"&SUM(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,1))))))),0,1)),0,0)
However, for Excel 2010 and later, MODE.MULT can be used instead...
H2, confirmed with CONTROL+SHIFT+ENTER:
=LINEST(INDEX($B:$B,N(IF(1,MODE.MULT(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($A$2:$A$10)*{1,1}))))))),INDEX($C:$C,N(IF(1,MODE.MULT(IF($A$2:$A$10>=F2,IF($A$2:$A$10<=G2,IF($D$2:$D$10=1,ROW($A$2:$A$10)*{1,1}))))))),0,0)
Hope this helps!

Excel, more efficient formula for multiple IF ANDS

I have a spreadsheet that I am making that looks as follows:
Index Diff Exc Sym Sec Result Criteria Met
3.42 -2.07 0.86 0.92 1.83 1.95
-0.38 -2.93 0.87 0.23 -2.01 0.09
-2.67 -1.84 0.87 -2.49 -3.48 1.32
-0.65 -0.98 0.46 0.98 -2.01 0.00
-0.73 -2.79 -1.07 -2.15 -1.44 -0.10
0.15 2.33 -0.46 -0.66 3.17 0.38 0.38
0.90 -3.68 -0.72 -1.01 -1.36 1.69
0.68 -1.12 -0.36 0.73 -1.34 -0.29
-1.19 -1.70 -0.56 -1.31 1.45 0.49
-0.45 -0.69 -0.56 -1.22 0.00 -0.49
2.94 8.38 2.21 6.25 4.96 1.74
-1.04 7.36 2.59 3.00 2.17 2.97
1.21 1.73 3.05 1.48 3.56 0.77
-1.10 1.86 0.60 1.18 1.07 -0.49
-0.89 -3.19 -1.78 -2.24 -4.26 -0.81
-1.17 -3.44 0.11 -1.22 3.66 0.36
0.52 0.92 -1.02 0.38 1.96 -1.40 -1.40
-0.90 3.01 -0.86 0.62 0.97 -0.50 -0.50
2.78 1.46 0.00 0.47 1.95 0.84
Max Min
Index 2.00 -2.00
Diff 10.00 0.00
Exc 0.00 -10.00
Sym 10.00 -10.00
Sec 20.00 0.00
Under the headings Index, Diff, Exc, Sym, Sec, Result is all data, In the criteria met column i have a formula that checks if the prior headings fall within the Max and Min limits of the smaller table underneath, and if they do it posts the result, if they dont all fall within the Max and Min boundaries it leaves it blank. I did that by using this formula:
=IF(AND(A3<$B$24,A3>$C$24,B3<$B$25,B3>$C$25,C3<$B$26,C3>$C$26,D3<$B$27,D3>$C$27,E3<$B$28,E3>$C$28),F3,"")
copied down the criteria met column. It works perfectly fine for what I want it to achieve but as this spreadsheet grows and I add more columns it seems like it will be incredibly inefficient and prone to alot of human error. Is there a way to achieve the same results but by using a more efficient formula?
a picture for reference as well:
Try this array formula:
=IF(SUM((A3:E3<=TRANSPOSE($B$24:$B$28))*(A3:E3>= TRANSPOSE($C$24:$C$28)))=COLUMNS(A3:E3),F3,"")
Being an Array Formula it must be confirmed with Ctrl-Shift-Enter when exiting Edit mode. When done correctly Excel will automatically put {} around the formula to denote an array formula.
One caveat, the Columns to be compared need to be in the same order as the min/max rows.
Also, as has been stated by nearly everyone if the Min Max were transposed to rows from column it would alleviate needing to use a CSE array formula. The following would work:
=IF(SUMPRODUCT((A5:E5>=$A$3:$E$3)*(A5:E5<=$A$2:$E$2))=COLUMNS(A5:E5),F5,"")
Try something like this:
=IF(PRODUCT(IF(ROW>TRANSPOSE(MIN),1,0),IF(ROW<TRANSPOSE(MAX),1,0))=1,RESULT,"")
In this example, A11:E11 is a row of data with RESULT in F11 and the MAX and MIN criteria are in $B$27:$B$31 and $C$27:$C$31, respectively.
=IF(PRODUCT(IF(A11:E11>TRANSPOSE($C$27:$C$31),1,0),IF(A11:E11<TRANSPOSE($B$27:$B$31),1,0))=1,F11,"")
Enter the expression as an array formula (CTRL-SHIFT-ENTER). Make sure to use a relative reference for each row of data and absolute references for the MAX and MIN criteria. Then copy/paste to evaluate other rows. Modifying this formula to accommodate additional columns of data can be done by extending the ranges.
If you are permitted to transpose the range that holds the MAX and MIN criteria to the same orientation as the data, the TRANSPOSE functions in this solution can be eliminated and the spreadsheet layout will be cleaner.
Hope that helps
How about:
=IF(AND(A3=MEDIAN(A3,B$24,C$24),B3=MEDIAN(B3,B$25,$C$25),C3=MEDIAN(C3,B$26,$C$26‌​),D3=MEDIAN(D3,B$27,$C$27),E3=MEDIAN(E3,B$28,$C$28)),F3,"")
I would also move the criteria table into a separate tab to avoid that you have to adjust the loacation of the min/max values in your formula every time you add new rows to your data table.
Often in Excel, in order to simplify your formulas, you need to make your layout a little more complex. Without writing any vba, my approach would be ...
1) I would transpose your min / max layout and have them align with the columns of data.
2) Insert another sheet to hold intermediate calculations.
Here's Sheet1 ...
and here's Sheet2 ...
In Sheet2, cell B5 contains a typical formula ...
=IF(AND(Sheet1!B5<Sheet1!B$2,Sheet1!B5>Sheet1!B$3),1,0)
In Sheet2, cell G5 (and down) contains ...
=PRODUCT(B5:F5)
In Sheet1, cell H5 (and down) contains ...
=IF(Sheet2!G5=0,"",Sheet2!G5*G5)
It could omit the logic and you could make the sheet settings to not display 0 values.
If you add columns (e.g. insert columns between Sheet1 column F and G):
- add Max and Min values for new columns on Sheet1
- insert the same columns on Sheet2
- drag the formula from column F on sheet2 to the new columns on Sheet2
- verify the Product formula in the "Result" column on Sheet2 contains the new columns on Sheet2.
This method helps identify exactly what caused you to fail to meet your criteria.

Align two time series where each has gaps

I am trying to merge two variables with different dates together using Excel. Here is an example of what I am trying to do:
Date Y Date X
03.01.2005 2.56438 03.01.2005 2.154
04.01.2005 2.57 04.01.2005 2.151
05.01.2005 2.59 05.01.2005 2.151
06.01.2005 2.61 06.01.2005 2.15
07.01.2005 2.61 07.01.2005 2.146
10.01.2005 2.62 08.01.2005 2.146
11.01.2005 2.63 09.01.2005 2.146
12.01.2005 2.64 10.01.2005 2.145
13.01.2005 2.66 11.01.2005 2.144
14.01.2005 2.66 12.01.2005 2.144
17.01.2005 2.67 13.01.2005 2.143
18.01.2005 2.67 14.01.2005 2.144
19.01.2005 2.68 15.01.2005 2.143
20.01.2005 2.6925 16.01.2005 2.144
21.01.2005 2.7 17.01.2005 2.143
24.01.2005 2.7 18.01.2005 2.143
25.01.2005 2.7 19.01.2005 2.144
X has values on dates when there is no Y value (e.g. 08.01.2005).
Is it possible to create a new column (say col5) that only contains the date if it can be found for both variables and then add the values for Y(col6) and X(col7) behind it? (I.e. in my case the date 08.01.2005 would be skipped since it can only be found for the variable X but not for the variable Y).
At the end it should look like:
Z Y X
03.01.2005 2.56438 2.154
04.01.2005 2.57 2.151
05.01.2005 2.59 2.151
06.01.2005 2.61 2.15
07.01.2005 2.61 2.146
10.01.2005 2.62 2.145
11.01.2005 2.63 2.144
12.01.2005 2.64 2.144
13.01.2005 2.66 2.143
14.01.2005 2.66 2.144
17.01.2005 2.67 2.143
18.01.2005 2.67 2.143
19.01.2005 2.68 2.144
Note that sometimes it is also the other way around, meaning there are dates with a value for Y but not for X.
Create a list of all possible dates on or between your limits, use VLOOKUP to populate an array including this list with Y and X from your source data then filter the array to delete rows that show #N/A.
If Date is in A1 and your list of dates in ColumnF starting in Row2, in G2:
=VLOOKUP(F2,A:B,2,0)
in H2:
=VLOOKUP(F2,C:D,2,0)
Copy both down to suit then select ColumnsF:H, Copy into a new sheet with Paste Special, Values and filter to delete rows containing #N/A. Copy result back if required.

Excel three column duplication and averaging

I need to average data (3rd column) corresponding to a specific latitude and longitude(1st and 2nd columns). The results are then outputted to columns 4,5,6.
Sample data and manual analysis is posted bellow. I think I need Index, Iferror or Vlookup. Most of the other questions dealing with this kind of work only typically consider 1 variable, not two.
Latitude Longitude Data UniqueLat UniqueLong Average of data
24.4000 -82.5000 13.1 24.4000 -82.5000 13.15
24.4000 -82.5000 13.2 24.4000 -82.4000 15.25
24.4000 -82.4000 17.8 24.5000 -82.4000 13.4
24.4000 -82.4000 12.7 24.5000 -82.1000 14.56
24.5000 -82.4000 13.4 24.6000 -82.0000 18
24.5000 -82.1000 16
24.5000 -82.1000 15.1
24.5000 -82.1000 13.3
24.5000 -82.1000 15.1
24.5000 -82.1000 13.3
24.6000 -82.0000 15.6
24.6000 -82.0000 20.4
I have a second problem related to this original question;
I need to compare my list of latitude/longitude (columns 4 and 5) with the values outputted from the Pivot table containing the latitude/longitude data (columns 1 and 2) and its associated data (column 3). This associated data I need to ascribe to the relevant latitude and longitude in column 6.
I have tried to use the index functionality etc but have had little luck.
Let me know if you can help at all with this second part.
DatabaseLat DatabaseLon Data Lat Lon CopiedData
31.2 -87.9 5 30.5 -87.1 3
31.9 -88.3 6 31.9 -88.4 10
31.9 -88.4 10 54 -87.1
31.1 -87.2 2 31.2 -87.9 5
30.5 -87.1 3
Just use a pivot table:
Select all the data (including headers) in columns Latitude, Longitude, and Data.
Choose Insert > PivotTable.
Drag Latitude and Longitude into the Row Labels section.
Choose PivotTable Tools > Design > Report Layout > Show in Tabular Form and Repeat All Item Levels. Also choose to turn off Grand Totals and Subtotals.
Drag the Data column into the Values section.
Hit the drop-down for Data and change the Value Field Settings... to average.
All said and told, the results should like this:
For the first part I would use an averageifs formula.
For the second part if you are guaranteed that the list you are looking up is unique (I think it is from what you said) you could just use a sumifs to then find the value next to that lat and long.

Calculating a work week based on weekly time-sheet

I am trying to calculate work week hours which I want to match it with the company's paycheck earned amount. So far I have this:
7/12/2011 7.90
7/13/2011 8.03
7/14/2011 7.83
7/15/2011 7.97
7/18/2011 8.20
7/19/2011 8.12
7/20/2011 8.15
7/21/2011 6.07
7/22/2011 8.12
7/25/2011 8.13
7/26/2011 8.1
7/27/2011 8.4
7/29/2011 8.27
8/1/2011 8.33
8/2/2011 8.18
8/3/2011 8.22
8/4/2011 6.72
8/5/2011 7.57
8/8/2011 8.07
8/9/2011 8.28
8/10/2011 5.8
8/11/2011 8.8
8/15/2011 8.2
8/16/2011 7.95
8/17/2011 8.17
8/18/2011 8.1
8/19/2011 7.8
8/22/2011 8.18
8/23/2011 9.7
8/24/2011 8.17
8/25/2011 8.18
and want to match the total to this:
Check Date Earnings Start Earnings End Earn Type Earn Amount
8/10/2011 7/26/2011 8/10/2011 Salary 899.6
8/25/2011 8/11/2011 8/25/2011 Salary 888.28
The company's pay period varies, that's why these days don't follow.
So far I was using =SUMIFS functions but they are not giving the result I need.
Let me know if there's clarifications anyone needs!
You should be able to use =SUMIFS() to get the hours during the pay period.
=SUMIFS(B:B,A:A,">="&F4,A:A,"<="&G4)
Here,
column A contains the dates,
column B contains the hours,
cell F4 is the Earnings start date,
cell G4 is the Earnings end date.

Resources