I wrote a nested loop based on columns (A,B & C) and placed it into column D2 and dragged it down to D15 but it seems to stop working when it hits the sports section with remaining values as FALSE
=IF(A2="fruit","fruit",
IF(A2="instrument","instrument",
IF(A2="colours",
IF(B2="red","red",
IF(B2="orange","orange",
IF(A2="sports",
IF(B2="soccer","soccer",
IF(B2="basketball","basketball",
IF(A2="fighting",
IF(B2="taekwando","taekwando",
IF(B2="boxing","boxing",
IF(B2="blood",
IF(C2="mma","mma",
IF(C2="ufc","ufc",
IF(A2="planets",
IF(B2="earth","earth",
IF(B2="dwarf",
IF(C2="pluto","pluto",
IF(A2="cars",
IF(B2="ford","ford",
IF(B2="toyota","toyota")))))))))))))))))))))
Not sure where I am going wrong with the nested loop but it fails when it hits the sports group and produces FALSE for the remaining values in column D
______A_____ _____B_____ ______C_____ _____D______
1|Product |Category |Sub-category|Result |
2|fruit |fruit | |fruit |
3|instrument |instrument | |instrument |
4|colours |red | |red |
5|colours |orange | |orange |
6|sports |soccer | |FALSE | <-- failure starts here
7|sports |basketball | |FALSE |
8|fighting |taekwando | |FALSE |
9|fighting |boxing | |FALSE |
10|fighting |blood |mma |FALSE |
11|fighting |blood |ufc |FALSE |
12|planets |earth | |FALSE |
13|planets |pluto |dwarf |FALSE |
14|cars |ford | |FALSE |
15|cars |toyota | |FALSE |
Would appreciate some help to improve the formula to return the values as indicated in the forumla
If you are just trying to get the last non-empty (sub) category :
=IF(C2 > "", C2, B2)
As i tried to reproduce the issue, I think the brackets are messed.
Please try using IFS where you need multiple nested conditions so that you can reduce the complexity of the code. Try the below snippet.
=IF(A7="fruit","fruit",
IF(A7="instrument","instrument",
IF(A7="colours",
IFS(B7="red","red",B7="orange","orange"),
IF(A7="sports",
IFS(B7="soccer","soccer",B7="basketball","basketball"),
IF(A7="cars",
IFS(B7="ford","ford",B7="toyota","toyota"))))))
Hope this helps.
using formula given by #Ashwin (thank you!) i improved it to include all categories. This seems to be working as expected.
=IF(A2="fruit","fruit",
IF(A2="instrument","instrument",
IF(A2="colours",
IFS(B2="red","red",B2="orange","orange"),
IF(A2="sports",
IFS(B2="soccer","soccer",B2="basketball","basketball"),
IF(A2="fighting",
IFS(B2="taekwando","taekwando",B2="boxing","boxing",B2="blood",IF(C2="mma","mma",IF(C2="ufc","ufc","not met"))),
IF(A2="planets",
IFS(B2="earth","earth",B2="dwarf",IF(C2="pluto","pluto","not met")),
IF(A2="cars",
IFS(B2="ford","ford",B2="toyota","toyota"))))))))
Related
I have a data range with dummy data and I want to make a query that returns only the headers when the sum of the columns is higher than 0. My first attempt has been to at least try to make a query that returns the columns for which Sum(Column)>0 by using this formula:
=query(A1:D,"Select A, B, C, D, WHERE SUM(A)>0 AND SUM(B)>0 AND SUM(C)>0 AND SUM(D)>0",0)
But I haven't had any luck. Here is a sample of a dummy table. I would very much appreciate any pointers in this matter.
| Dog| Cow | Cat|Horse|
|:---|:---:|:--:|----:|
| 1 | 0 |2 |3 |
| 2 | 0 |4 |6 |
| 3 | 0 |6 |9 |
| 4 | 0 |8 |12 |
A simple approach would be:
=query({A:D},"Select "&if(sum(A2:A)>0,"Col1",)&if(sum(B2:B)>0,",Col2",)&if(sum(C2:C)>0,",Col3",)&if(sum(D2:D)>0,",Col4",)&" ",1)
I tried to do group by in SparkSQL which works good but most of the rows went missing.
spark.sql(
"""
| SELECT
| website_session_id,
| MIN(website_pageview_id) as min_pv_id
|
| FROM website_pageviews
| GROUP BY website_session_id
| ORDER BY website_session_id
|
|
|""".stripMargin).show(10,truncate = false)
I am getting output like this :
+------------------+---------+
|website_session_id|min_pv_id|
+------------------+---------+
|1 |1 |
|10 |15 |
|100 |168 |
|1000 |1910 |
|10000 |20022 |
|100000 |227964 |
|100001 |227966 |
|100002 |227967 |
|100003 |227970 |
|100004 |227973 |
+------------------+---------+
Same query in MySQL gives the desired result like this :
What is the best way to do ,so that all rows are fetched in my Query.
Please note I already checked other answers related to this, like joining to get all rows etc, but I want to know if there is any other way by with we can get the result like we get in MySQL ?
It looks like it is ordered by alphabetically, in which case 10 comes before 2.
You might want to check that the columns type is a number, not string.
What datatypes do the columns have (printSchema())?
I think website_session_id is of string type. Cast it to an integer type and see what you get:
spark.sql(
"""
| SELECT
| CAST(website_session_id AS int) as website_session_id,
| MIN(website_pageview_id) as min_pv_id
|
| FROM website_pageviews
| GROUP BY website_session_id
| ORDER BY website_session_id
|
|
|""".stripMargin).show(10,truncate = false)
Why does the following Excel MATCH function not return the 'Matched' values?
{=MATCH($A2, $C$2:$C$4,0)}
I have been struggling with an Excel MATCH function for a long time now.
I have created what is essentially the same MATCH function below on a much simplified data set (motor manufacturers), however even the simplified version is not working.
Please could someone help explain why.
For reference:
All cells are formatted as 'Text' apart from the cell I am putting
the formula in. I have also tried 'General' formatting.
There are no special characters or whitespace in either the lookup
value column or the lookup array column.
I have entered the formula using Ctrl+Shift+Enter to create an array
formula (I also tried without, but neither work).
I have ordered both columns in descending (A-Z) order (even though I
don't think I need this for match type '0' (Exact).
Below is my sample 'file'.
________________________________________________________________________________________
|RowNum |A Lookup Value |B MATCH Formula |C Lookup Array |D Equal to Formula |
|1 |Text - String |=MATCH($A2, $C$2:$C$4,0) |String |e.g. =A6=C2 |
|-------|---------------|-------------------------|---------------|-------------------|
|2 |aston martin |#N/A |ford |TRUE |
|3 |audi |#N/A |jeep |TRUE |
|4 |bugatti |#N/A |lotus |TRUE |
|5 |chevrolet |#N/A | | |
|6 |ford |#N/A | | |
|7 |infiniti |#N/A | | |
|8 |jeep |#N/A | | |
|9 |land rover |#N/A | | |
|10 |lexus |#N/A | | |
|11 |lotus |#N/A | | |
|12 |maserati |#N/A | | |
|13 |mazda |#N/A | | |
|14 |mclaren |#N/A | | |
---------------------------------------------------------------------------------------
I suspect you have calculation set to manual. Since the first formula would return #N/A, when filled down, they will all return the same value.
The calculation mode for an Excel session defaults to the saved mode of the first workbook opened, so if you opened a workbook that someone had saved with manual calculation, then opened a new workbook, calculation would have been set to manual without you doing anything.
I've been trying to use AVERAGE with INDIRECT but keeps giving me errors.
Now I am using Average like this:
AVERAGE(Results!C2:C51)
I need to get data from another sheet "Results". But in my current sheet I got the range of the rows set in two cells.
+-------------------+
| ... E F |
| +-------+-------+
| 2 |...| 2 | 51| |
| +---------------+
| 3 | | 52|101| |
| +---------------+
| 4 | | | | |
+---+---+---+---+---+
I've tried like this, but it's not working:
AVERAGE(Results!INDIRECT("C"&E2):INDIRECT("C"&F2))
This should do it:
=AVERAGE(INDIRECT("Results!C"&E2&":C"&F2))
The answer posted by zipa is correct. Here is an alternaive that will allow you to avoid INDIRECT() entirely:
=AVERAGE(INDEX(Results!C:C,E2):INDEX(Results!C:C,F2))
This is based on Scott Craner's Answer to a question I asked previously.
I have a very somewhat complicated question (at least to me ) and I'm hoping someone will be kind enough to help. I hope my explanation is good enough
I have a mapping table like below, we have multiple elements b mapped to element a
| Element a |Element b|
|---------------|-------- |
| B10 | 212010 |
| B101 | 212010 |
| B102 | 212010 |
| B103 | 212010 |
| B104 | 212010 |
| B301 | 111030 |
| B302 | 111030 |
| B303 | 111030 |
| B304 | 111030 |
|---------------|-------- |
Each element in the above table will have a value in another table:
| Element A | Value |
|-----------|-------------|
| B10 | 1,000.00 |
| B101 | 2,000.00 |
| B102 | 6,000.00 |
| B103 | 1,000.00 |
| B104 | 10,000.00 |
| B301 | 1,000.00 |
| B302 | 2,000.00 |
| B303 | 6,000.00 |
| B304 | 1,000.00 |
|-----------|-------------|
| Element B | Value |
|-----------|-------------|
| 212010 | 20,000.00 |
| 111030 | 10,000.00 |
|-----------|-------------|
I have to compare the value of the corresponding elements above using the mapping table, I'm looking for a solution that looks like the table below -
Steps:
Compare the value of each element side by side without duplicating element b
if possible put a box around each mapped element and value
I understand it may only be possible to the above using only VBA macros, but a similar solution using only excel formula will be very appreciated.
The solution should be compatible with Excel 2003.
Thank you very much
Insert a column after element a and insert formula:
=VLOOKUP(A2;$F$2:$G$7;2;FALSE)
$F$2:$G$7 should refer to the sheet/range of your values
the column after element b should contain the formula:
=IF(C2<>C1;VLOOKUP(C2;$F$2:$G$7;2;FALSE);"")
Then put a conditional format in for the border based on the cell in d column being empty or not.
Go to conditional formating and select "use formula"
type in formula:
$D2<>""
And select the tab border to select top border.
I would do this by sql query in excel if you have these tables in different sheets you can join them.
In sql after select statement you can type Distinct and this will delete the duplicates.