Set certain values in column B by matching it to another pair of columns - vba

In First sheet I have many rows (but less than 10 thousand rows)
A B
198
198
198
197
197
225
…
…
…
119
229
In a Second sheet I have the matching values (some will be empty e.g 8.6 has no pair). Values in A are not sequential, while B is sequential from 0.1 to 21.1 (0.1 interval)
A B
139 0.1
211 0.2
208 0.3
208 0.3
207 0.4
…
…
…
229 4.0
…
…
…
119 7.4
…
…
…
- 8.6
198 8.5
197 8.7
…
…
…
225 9.9
After the macro/VBA I want the result in the First sheet, such as: (please can someone give me some hints, thank you very much)
A B
198 8.5
198 8.5
198 8.5
197 8.7
197 8.7
225 9.9
…
…
…
119 7.4
229 4.0

In the first sheet, use a VLOOKUP function to find corresponding matches in the second sheet (I'll call that Sheet2. with IFERROR to catch no matches. In the first sheet's B2 cell, use this formula,
=IFERROR(VLOOKUP($A2, 'Sheet2'!$A:$B, 2, FALSE), "")
VLOOKUP function
That will return the first value in column B that corresponds to a matching value in column A which seems to be what you want. Other options would be SUMIF, AVERAGEIF and/or COUNTIF.

Related

Creating a Lookup Matrix in Microsoft Access

I have the matrix below in Excel and want to import it into Access (2016) to then use in queries. The aim is to be able to lookup values based on the row and column. Eg lookup criteria of 10 and 117 should return 98.1.
Is this possible? I'm an Access novice and don't know where to start.
.
10
9
8
7
6
5
4
3
2
1
0
120
100.0
96.8
92.6
86.7
78.8
68.2
54.4
37.5
21.3
8.3
0.0
119
99.4
96.2
92.0
86.2
78.5
67.9
54.3
37.5
21.3
8.3
0.0
118
98.7
95.6
91.5
85.8
78.1
67.7
54.1
37.4
21.2
8.3
0.0
117
98.1
95.1
90.9
85.3
77.8
67.4
54.0
37.4
21.2
8.3
0.0
116
97.4
94.5
90.3
84.8
77.4
67.1
53.8
37.4
21.1
8.3
0.0
115
96.8
93.9
89.8
84.4
77.1
66.9
53.7
37.3
21.1
8.3
0.0
Consider creating a table with 3 columns to store this data:
Value1 - numeric
Value2 - numeric
LookupValue - currency
You can then use DLookup to get the value required:
?DLookup("LookupValue","LookupData","Value1=117 AND Value2=10")
If you have the values stored in variables, then you need to concatenate them in:
lngValue1=117
lngValue2=10
Debug.Print DLookup("LookupValue","LookupData","Value1=" & lngValue1 & " AND Value2=" & lngValue2)

Dynamically Calculate difference columns based off slicer- POWERBI

I have a table with quarterly volume data, and a slicer that allows you to choose what quarter/year you want to see volume per code for. The slicer has 2019Q1 through 2021Q4 selections. I need to create dynamic difference column that will adjust depending on what quarter/year is selected in the slicer. I know I need to create a new measure using Calculate/filter but am a beginner in PowerBI and am unsure how to write that formula.
Example of raw table data:
Code
2019Q1
2019Q2
2019Q3
2019Q
2020Q1
2020Q2
2020Q3
2020Q4
11111
232
283
289
19
222
283
289
19
22222
117
481
231
31
232
286
2
19
11111
232
397
94
444
232
553
0
188
22222
117
411
15
14
232
283
25
189
Example if 2019Q1 and 2020Q1 are selected:
Code
2019Q1
2020Q1
Difference
11111
232
222
10
22222
117
481
-364
11111
232
397
-165
22222
117
411
-294
Power BI doesn't work that way. This is an Excel pivot table setup. You don't have any parameter to distinguish first and third or second and fourth row. They have the same code, so Power BI will aggregate their volumes. You could introduce a hidden index column but then why don't you simply stick to Excel? The Power BI approch to the problem would be to unpivot (stack) your table to a Code, Quarter and a Volume column, create 2 independent slicer tables for Minuend and Subtrahend and then CALCULATE your aggregated differences based on the SELECTEDVALUE of the 2 slicers.

Postgres - How to convert row with an int range into intermediate rows from individual values from that range?

Initial input:
CREATE TABLE TEST_TABLE(
start_i INT,
end_i INT,
v REAL
);
INSERT INTO TEST_TABLE (start_i, end_i, v)
VALUES (300,305,0.5),
(313,316,0.25)
start_i
end_i
v
300
305
0.5
313
316
0.25
Desired outcome:
Basically, I want to create intermediate rows with an additional column containing each value in the ranges shown in the initial table.
i
start_i
end_i
v
300
300
305
0.5
301
300
305
0.5
302
300
305
0.5
303
300
305
0.5
304
300
305
0.5
305
300
305
0.5
313
313
316
0.25
314
313
316
0.25
315
313
316
0.25
316
313
316
0.25
I have checked this post, but it's for SQL Server, while I am interested in Postgres. In addition, I am not using a date column type, but an integer instead.
Use generate_series():
select gs.i, t.*
from t cross join lateral
generate_series(start_i, end_i, 1) gs(i);
Strictly speak, the lateral is not needed. But it does explain what is going on. I should also note that you can also do:
select generate_series(start_i, end_i) as i, t.*
from t;
However, generate_series() affects the number of rows in the query. I am uncomfortable with having such effects in the SELECT clause.

Generate Seaborn Countplot using column value as count

For the following table
count_value
CPUCore Offline_RetentionAge
i7 183 4184
7 1981
30 471
i5 183 2327
7 831
30 250
Pentium 183 333
7 125
30 43
2 183 575
7 236
31 96
Is it possible to generate a seaborn countplot (or normal countplot) like the following (generated using sns.countplot(x='CPUCore', hue="Offline_BackupSchemaIncrementType", data=dfCombined_df))
Problem here is that I need to use the count_value as count, rather then really go and count the Offline_RetentionAge
I think you need seaborn.barplot:
sns.barplot(x="count_value", y="index", hue='Offline_RetentionAge', data=df.reset_index())

How to read data on a specific row from excel by asking the name of that row?

I have the following excel file:
W1000x554 1032 408 52.1 29.5 70700 12300
W1000x539 1030 407 51.1 28.4 68700 12000
W1000x483 1020 404 46 25.4 61500 10700
W1000x443 1012 402 41.9 23.6 56400 9670
W1000x412 1008 402 40 21.1 52500 9100
W1000x371 1000 400 36.1 19 47300 8140
W1000x321 990 400 31 16.5 40900 6960
W1000x296 982 400 27.1 16.5 37800 6200
W1000x584 1056 314 64 36.1 74500 12500
I want to define a function that can ask the user for one of the first column's names and then read all the relevant data of that row later.
For example if the user defines W1000x412 then read : 1008 402 40 21.1 52500 9100.
Any ideas?
I suspect what #Marc means is that a formula such as in J2 below (copied across and down as necessary) will 'pick out' the values you want. It is not clear to me from your question whether these should be kept separate (as in Row2 of example) or strung together (CONCATENATE [&] as in J7 of example, where these are space [" "] delimited):
I am also not entirely sure about your 'define a function' but have assumed you do not require a UDF.
I have used Row1 to provide the offset for VLOOKUP, to save adjusting manually the formula for each column.
ColumnI is the expected user input, that might be best by selection from a Data Validation List with Source $A$2:$A$10.