Nested IF(AND(OR statement - excel

Here is my current formula
=IF(OM2=0,"No",IF(OM2=4(OR(5,11,12,16,17))*AND(F2="Double"),"Yes",IF(OM2=1(OR(2,3,6,7,8,9,10,13,14,15))*AND(F2="Triple"),"Yes","No")))
I'm trying to get OU to be yes if OM is 4,5,11,12,16,or 17 and F is Double.
Also, to get OU to be yes if OM is 1,2,3,6,7,8,9,10,13,or 15 and F is Triple.
I have checked F2 and it correctly results "Double" or "Triple" accordingly with correct spelling and no extra spaces.
I am still getting "No" being resulted, see pic below:
Thanks for any help!

Try to write OR(OM2 = x, OM2=y, OM2 = z ...) instead of what you wrote.
This should work.

As the other responders said you should really think about making a lookup tables.
In addition, if you use Excel 2013 onwards, it is much easier if you convert your normal table into "Excel" table (Ctrl - T will do it). Google more about "Excel tables" to learn about their benefits vs traditional tables.
After that, set up 2 lookup tables, Table 1 and Table 2 (they themselves should also be Excel tables) as in the photo.
Then your formula will be:
=OR(SUMPRODUCT(--(Table1[OM]=[#OM]),--(Table1[F]=[#F])),SUMPRODUCT(--(Table2[OM]=[#OM]),--(Table2[F]=[#F])))
When you write up this formula, you can just select the cells in the respective lookup tables, Excel will automatically turn them into table named ranges as you see above.

Another option would be to use a lookup table to map your value of OM to the expected value of OU.
For example, if you had a sheet named "Lookup" with the following data:
| A | B
1 | 1 | Triple
2 | 2 | Triple
...
5 | 5 | Double
Then you could use something like
IF(VLOOKUP(OM2,Lookup!$A$1:$B$16,2,FALSE)=OU2,"Yes","No")

Related

Excel replace equation of ID by equation of values

I have an excel column with multiple equation of ID like that for example :
56+78+(98&63)
32+87+21
12+(77&96&31)
And i have an other excel file with 2 columns (The ID and the correspond text) :
56 | ABC
78 | BCD
98 | GBF
63 | JIM
And i would like to replace in ID in equation by the corresponding text so it becomes :
56+78+(98&63) => ABC+BCD+(GBF&JIM)
I just know some easy formula, tried to combine some REPLACE, SEARCH, LOOKUP fucntion but didn't worked.
Thanks in advance for helping !
For this it would be easy to have access to LET() and dynamic arrays through Microsoft Excel 365:
Formula in B1:
=LET(X,MID(A1,SEQUENCE(LEN(A1)),1),Y,FILTERXML(SUBSTITUTE(CONCAT("<t><s>",IF(ISNUMBER(--X),X,"</s><s>"&X&"</s><s>"),"</s></t>"),"&","&"),"//s[.!='']"),CONCAT(IFERROR(VLOOKUP(Y,C$1:D$4,2,0),Y)))
As you can see, no translations in your 2nd and 3rd samples since it couldn't find a proper translation in your lookup-table.

sum values of cells in google sheets if the result of their sum with adjacent cell meets a condition

Suppose I have the following data in a spreadsheet, where the first row contains the column headings and the first column contains the row index (for reference):
||A | B | C |
==||================
0 ||2 | 3 | Y |
--||----------------
1 ||2 | 4 | Y |
--||----------------
2 ||3 | 5 | N |
--||----------------
3 ||8 | 3 | Y |
--||----------------
How can I get the sum of all the values in column B for which b - a >= 1 && c == "Y", in Google Sheets and Excel?
So essentially, the sum should factor in only rows 0 and 1 in which case the result should be 7.
I know this sounds like a very specific question but I did not know how else to describe it other than by example. The answer should be applicable in other similar scenarios.
Thanks for the help.
[Edit] In response to people voting down due to lack of research, well, I've tried to use the sumif() function but I got stuck immediately on the condition part as I am not sure how to compare the current item in the aggregation with another cell. I also tried to use the sumifs() function which allows for multiple criteria, but also to no avail. As for my research, I searched on Google but could not find anything, possibly due to my inability to express the requirement in a manner suitable for a google query. Therefore, I have presented the above as a way of explaining my requirement by example.
I hope this helps.
I appreciate that this may not be possible to do with the simple built in formulas. If this is the case, please mention it as that would also be useful to know.
Thank you.
Excel: =SUMPRODUCT(((B:B-A:A)>=1)*(C:C="Y")*(B:B))
Untested, but let me know if it works. Next time, remember to add an example of code/formulas that you have already tried and what error you ran into.
Edit:
Tested it, here is a screenshot of it working with your example data (disregard the fact that my Excel is in spanish)
This works by intersecting both logical tests (that is, performing a logical AND): (B-A)>=1 AND C="Y". Here you can see the result of each logical test and then, finally, where it evaluates to TRUE it returns the value in column B; where it's FALSE, it returns 0. Finally, it sums the values in the result array.

Summing up a related table's values in PowerPivot/DAX

Say I have two tables. attrsTable:
file | attribute | value
------------------------
A | xdim | 5
A | ydim | 6
B | xdim | 7
B | ydim | 3
B | zdim | 2
C | xdim | 1
C | ydim | 7
sizeTable:
file | size
-----------
A | 17
B | 23
C | 34
I have these tables related via the 'file' field. I want a PowerPivot measure within attrsTable, whose calculation uses size. For example, let's say I want xdim+ydim/size for each of A, B, C. The calculations would be:
A: (5+6)/17
B: (7+3)/23
C: (1+7)/34
I want the measure to be generic enough so I can use slicers later on to slice by file or attribute. How do I accomplish this?
I tried:
dimPerSize := CALCULATE([value]/SUM(sizeTable[size])) # Calculates 0
dimPerSize := CALCULATE([value]/SUM(RELATED(sizeTable[size]))) # Produces an error
Any idea what I'm doing wrong? I'm probably missing some fundamental concepts here of how to use DAX with relationships.
Hi Redstreet,
taking a step back from your solution and the one proposed by Jacob, I think it might be useful to create another table that would aggregate all the calculations (especially given you probably have more than 2 tables with file-specific attributes).
So I have created one more table that contains (only) unique file names, and thus the relationships could be visualized this way:
It's much simpler to add necessary measures (no need for calculated columns). I have actually tested 2 scenarios:
1) create simple SUM measures for both Attribute Value and File Size. Then divide those two measures and job done :-).
2) use SUMX functions to have a bit more universal solution. Then the final formula for DimPerSize calculation could look like this:
=DIVIDE(
SUMX(DISTINCT(fileTable[file]),[Sum of AttrValue]),
SUMX(DISTINCT(fileTable[file]),[Sum of FileSize]),
BLANK()
)
With [Sum of AttrValue] being:
=SUM(attrsTable[value])
And Sum of FileSize being:
=SUM(sizeTable[size])
This worked perfectly fine, even though SUMX in both cases goes over all instances of given file name. So for file B it also calculates with zdim (if there is a need to filter this out, then use simple calculate / filter combination). In case of file size, I am using SUMX as well, even though it's not really needed since the table contains only 1 record for each file name. If there would be 2 instances, then use SUMX or AVERAGEX depending on the desired outcome.
This is the link to my source file in Excel (2010).
Hope this helps.
You look to have the concept of relationships OK but you aren't on the right track in terms of CALCULATE() either in terms of the structure or the fact that you can't simply use 'naked' numerical columns, they need to be packaged in some way.
Your desired approach is correct in that once you get a simple version of the thing running, you will be able to slice and dice it over any of your related dimensions.
Best practice is probably to build this up using several measures:
[xdim] = CALCULATE(SUM('attrstable'[value]), 'attrstable'[attribute] = "xdim")
[ydim] = CALCULATE(SUM('attrstable'[value]), 'attrstable'[attribute] = "ydim")
[dimPerSize] = ([xdim] + [ydim]) / VALUES('sizeTable'[size])
But depending on exactly how your pivot is set up, this is likely to also throw an error because it will try and use the whole 'size' column in your totals. There are two main strategies for dealing with this:
Use an 'iterative' formula such as SUX() or AVERAGEX() to iterate individually over the 'file' field and then adds up or averages for the total e.g.
[ItdimPerSize] = AVERAGEX(VALUES('sizeTable'[file]), [dimPerSize])
Depending on the maths you want to use, you might find that produce a useful average that you need to use SUMX but devide by the number of cases i.e. COUNTROWS('sizeTable'[file]).
You might decide that the totals are irrelevant and simply introduce an error handling element that will make them blank e.g.
[NtdimPerSize] = IF(HASONEVALUE('sizeTable'[file]),[dimPerSize],BLANK())
NB, all of this assumes that when you are creating your pivot that you are 'dragging in' the file field from the 'sizetable'.

Compare multiple columns, pull out only cells that appear in every column

I have 10 or so columns in my worksheet. Each column contains about 200 names, and there is no other data on the sheet.
What I'd like to do is create a new column that only contains the names that are common between the columns. So essentially compare each cell in each column to all the other cells in all the other columns, and only return the the common cells.
For example:
Column1 : name_A, name_C, name_F
Column2: name_C, name_B, name_D
Column3: name_C, name_Z, name_X
So in this example, the new column would only contain name_C, because it's the only value common to all three columns.
Is there any way to do this? My knowledge of Excel is quite poor, and I can't find anything similar to my problem online so I would appreciate any help.
Thanks for reading,
N
Put everything on a single spreadsheet and create a pivot table is probably more efficient than the algorithm you have on your mind.
here is my mock-up. I added extra names to demonstrate better
D(formula) has the easiest version. this will list only values that appear in all columns, but these will appear on the same lines as the corresponding name in column A, with blanks, and not sorted (giving D(result))
IF you would like all the names to appear the the top - as shown here in column E you can either sort your table (you will have to re-sort if the columns change) OR you can use my solution below:
get yourself the MoreFunc Addon for Excell ( here is the last working download link I found, and here is a good installation walk-through video )
once all is done select cells E1:E8, click the formula bar and type the following: =UNIQUEVALUES(IF(COUNTIF(A2:C9,A2:A9)=3,A2:A9,""))
accept the formula by clicking ctrl-shift-enter (this will create an array-formula and curly braces will appear around your formula)
A B C D(formula) D(result) E(result - sorted)
-------------------------------------------------------------------------------------------------------
1 | name_A name_C name_C =IF(COUNTIF($A$1:$C$8,A1)=3,A1,"") name_m
2 | name_C name_B name_Z =IF(COUNTIF($A$1:$C$8,A2)=3,A2,"") name_C name_C
3 | name_F name_D name_X =IF(COUNTIF($A$1:$C$8,A3)=3,A3,"")
4 | name_t name_o name_g =IF(COUNTIF($A$1:$C$8,A4)=3,A4,"")
5 | name_y name_p name_h =IF(COUNTIF($A$1:$C$8,A5)=3,A5,"")
6 | name_u name_k name_7 =IF(COUNTIF($A$1:$C$8,A6)=3,A6,"")
7 | name_i name_5 name_9 =IF(COUNTIF($A$1:$C$8,A7)=3,A7,"")
8 | name_m name_m name_m =IF(COUNTIF($A$1:$C$8,A8)=3,A8,"") name_m

EXCEL 2010: COUNTIF using SUB-TOTAL (from filter) with multi criteria

Program: Excel 2010
I have a large selection of data which I filter for various reasons, I have been able to use the following to count my sales when filtered, however I want to be able add a 2nd criteria to the mix.
New: count by value B11 and C12
(B11) = Store Name
(C12) = Product Name
=SUMPRODUCT(--($C$38:$C$1000=(B11)),SUBTOTAL(3,OFFSET($C$38,ROW($C$38:$C$1000)-ROW($C$38),0)))
I have tried variations of the following however I keep getting errors:
=SUMPRODUCT(--($C$38:$C$1000=(B11),SUBTOTAL(3,OFFSET($C$38,ROW($C$38:$C$1000)-ROW($C$38),0)),(--($C$38:$C$1000=(C12),SUBTOTAL(3,OFFSET($C$38,ROW($C$38:$C$1000)-ROW($C$38),0)))
|Prod |Store
---------------
|ABC |CDA
|DEF |XYZ
|GHI |TUV
|ABC |XYZ
Prod = ABC; Store = CDA; Result = 1 (not 2)
Please help :-)
I'm not very familiar with SUBTOTAL, but this seems to work fine:
=SUMPRODUCT(--($C$38:$C$1000=(B11)),--($B$38:$B$1000=(C12)),SUBTOTAL(3,OFFSET($C$38,ROW($C$38:$C$1000)-ROW($C$38),0)))
I just added --($B$38:$B$50=(C12)) neat the beginning between the two expressions in the SUMPRODUCT
Another option to simplify formulas is to introduce a helper column which indicates whether the row is visible or not, e.g. in Z38 copied down
=SUBTOTAL(3,B38)
Now for your count with 2 criteria you can use COUNTIFS like this
=COUNTIFS(C:C,B11,B:B,C12,Z:Z,1)

Resources