Array formula to solve distance matrix - excel

Help me with the following problem without adding any helper cells and changing the data:
"There are 8 cities in the country of Eight, A, B, C, D, E, F, G and H. Mr. Z decides to visit each city in his car starting from A. His planned itinerary is A-->B-->C-->D-->E-->F-->G-->H.
The distance between the cities is given in Table I."
Table I
Distance
A B C D E F G H
A 0 200
B 200 0 350
C 350 0 500
D 500 0 250
E 250 0 850
F 850 0 1250
G 1250 0 150
H 150 0
"Write a formula which takes the number of kms that Mr. Z has traveled from A as the input and displays the name of the city which is nearest to that point.
Mr. Z will enter the number of kms he has travelled from A in cell D30 and the name of the city nearest to the point will be displayed in E30"

Presumably a variation on the following (doesn't say can't hardcode cumulative sums)
=INDEX({"A","B","C","D","E","F","G","H"},MATCH(MIN(ABS({0,200,550,1050,1300,2150,3400,3350}-D30)),ABS({0,200,550,1050,1300,2150,3400,3350}-D30),0))

Related

Mean imputation based on certain Conditions

I have the below dataframe,
Category Value
A 100
A -
B -
C 50
D 200
D 400
D -
As you can see, there are some values which have the hyphen symbol '-'. I want to replace those hyphons with the means of the corresponding category.
In the example, there are two entries for "A" - One row with value 100 and other with hyphen. So the mean would be 100 itself. For B, since there are no valid values, the mean would be the mean of the entire column which would be (100+50+200+400/4 = 187.5). For C, no changes and for D, the hyphen will be replaced by 300 (same logic as for "A").
Output:
Category Value
A 100
A 100
B 187.5
C 50
D 200
D 400
D 300
Try:
df = df.replace("-", np.nan)
df["Value"] = pd.to_numeric(df["Value"])
avg = df["Value"].mean()
df["Value"] = df["Value"].fillna(
df.groupby("Category")["Value"].transform(
lambda x: avg if x.isna().all() else x.mean()
)
)
print(df)
Prints:
Category Value
0 A 100.0
1 A 100.0
2 B 187.5
3 C 50.0
4 D 200.0
5 D 400.0
6 D 300.0

z score height of childs using WHO growth standards data

I'm using the data of WHO child growth standards to program the calculus of z scores, and I have a problem with the calculation of the length z score, since in the data table lenanthro.txt when it changes from 730 to 731 days of age, just when the length term changes from lenght L to height H, there is a discontinuity in the value of M, which even decreases , that is impossible with the evolution of growth of a child, because having one more day of life would sharply increase the z score. Any ideas on how to deal with this discontinuity?
These are the data of that table (see the rows 730 and 731):
sex age l m s loh
1 0 1 49.8842 0.03795 L
1 1 1 50.0601 0.03785 L
......
1 729 1 87.7734 0.03478 L
1 730 1 87.8018 0.03479 L
1 731 1 87.1303 0.03508 H
1 732 1 87.1587 0.03509 H
....
Thank's

How to find a value in one column in another column and return cells in row where value was found

I want to find a value in column E, then get values from same row from columns B, C, and D. So I want to find 1 in column E, and the values from B, C, and E, then find 2 in column E and values from B, C, and D and all the way through 18.
I have tried VLOOKUP, INDEX/MATCH
B C D E
1 4 365 3
2 5 464 2
3 3 151 15
4 4 417 1
5 4 284 7
F G H I
1 4 4 417
2 2 5 464
3 1 4 365
G2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),1)
H2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),2)
I2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),3)
and fill down as far as needed, adjusting the array address as required.

SUMIFS across multiple sheets

So I'm working on a workbook right now that is across 3 sheets, 'Data', 'RAW', 'Lookup'. On the Data tab it looks like, Sheet 1
A B C D E
Segment Ranking Amount Revenue Spend
Carbon 15 2 5000 550
Oxygen 30 3 6895 450
Minerals 45 1 4400 350
The Code I use for each column are as follows (Some of the Columns are named columns)
B =IF(NOT(ISERROR(SEARCH("OK",$A2))),SUMIFS(RAW!B:B,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*"),SUMIFS(RAW!B:B,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*",Output,"<>*OK*"))
C =IF(NOT(ISERROR(SEARCH("OK",$A2))),SUMIFS(RAW!C:C,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*"),SUMIFS(RAW!C:C,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*",SegmentName,"<>*OK*"))
D =IF(NOT(ISERROR(SEARCH("OK",$A2))),SUMIFS(RAW!D:D,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*"),SUMIFS(RAW!D:D,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*",Output,"<>""OK"))
E =IF(NOT(ISERROR(SEARCH("OK",$A2))),SUMIFS(Spend,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*"),SUMIFS(Spend,Output,"*"&INDEX(SegmentID,MATCH($A2,SegmentName,0))&"*",Output,"<>*OK*"))
The RAW Sheet looks like (Sheet 2)
A B C D E
Output Ranking Amount Revenue Spend
Random_1234_Random 15 2 5000 550
Random_5678_Random 30 3 6895 450
Random_9102_Random 45 1 4400 350
Random_555_Random 60 4 4000 300
The Lookup Sheet Looks like (Sheet 3)
A B
Segment ID
Carbon 1234
Oxygen 5678
Minerals 9102
Carbon 555
The problem that I have right now is, it will only grab the first Carbon with ID 1234, and not grab the second Carbon with ID 555 at all resulting in:
A B C D E
Segment Ranking Amount Revenue Spend
Carbon 15 2 5000 550
The end result that I would like is for it to grab ALL Carbon with any ID and add all of them together as below into a single line. (RAW sheet, Random_1234_Random + Random_555_Random)
A B C D E
Segment Ranking Amount Revenue Spend
Carbon 75 6 9000 850
Any help would be great and if I need to provide more detail please let me know!
Thank you in advance,
Maykid

Excel Conditionally SUM rows totals

I have an excel like this:
I want to sum the totals by when (month), type and if it's in the budget. For example I want a result like this:
So... it "search" for every when with the same month, multiply the ammount but "in budget" column, and in sums everything by type that matches that.
I hope I explained well!! I think the result image will help!
Thanks a lot in advance!!
If you are prepared to generate another column (here: F) into your workbook like
A B C D E F
1 when curr type amnt budg
2 2 U F 85 1 F21
3 2 U T 50 1 T21
4 2 U T 150 1 T21
5 2 U T 380 1 T21
6 3 U G 600 1 G31
7 3 Y G 250 1 G31
8 6 U T 600 1 T61
9 9 U T 500 0 T90
[F2] = C2 & A2 & E2
[F3] = C3 & A3 & E3
...
Then you can do the sums with:
[A12] = sumif($F$2:$F$9, "F21", $A$2:$A$9) ' for when=2, type="F" and "in budget"
[A13] = sumif($F$2:$F$9, "T21", $A$2:$A$9) ' for when=2, type="T" and "in budget"
...

Resources