I wrote a formula which exceeds 8192 characters and I really need to reach the result of the formula. Actually it is repetetive calculation for different conditions. I'm sure when you see the formula you will get the idea. But there is short explanation below:
There are 10 different sources and regarding choosen source formula should work.
Regarding choosen currency I need to get result of related calculation.
Right now it is 10.290 chars.
Since this is my first question and I'm kinda new on Excel any help would be appreciated.
*Expected result need to be shown on "unit price" column and different for each item.
=IFERROR(IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="USD";core!$I29*core!$N$2+core!$I29*core!$N$2*core!$F29+core!$I29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3+core!$I29*core!$N$3*core!$F29+core!$I29*core!$N$3*core!$g29;"")));
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$I29/core!$N$2+core!$I29/core!$N$2*core!$F29+core!$I29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3/core!$N$2+core!$I29*core!$N$3/core!$N$2*core!$F29+core!$I29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";(core!$I29/core!$N$3+core!$I29/core!$N$3*core!$F29+core!$I29/core!$N$3*core!$g29);IF(core!$H29="USD";(core!$I29*core!$N$2/core!$N$3+core!$I29*core!$N$2/core!$N$3*core!$F29+core!$I29*core!$N$2/core!$N$3*core!$g29);IF(core!$H29="EURO";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;""))))))))))));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;IF(core!$H29="USD";core!$K29*core!$N$2+core!$K29*core!$N$2*core!$F29+core!$K29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$K29*core!$N$3+core!$K29*core!$N$3*core!$F29+core!$K29*core!$N$3*core!$g29;"")));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$K29/core!$N$2+core!$K29/core!$N$2*core!$F29+core!$K29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;IF(core!$H29="EURO";core!$K29*core!$N$3/core!$N$2+core!$K29*core!$N$3/core!$N$2*core!$F29+core!$K29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=2;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$K29/core!$N$3+core!$K29/core!$N$3*core!$F29+core!$K29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$K29*core!$N$2/core!$N$3+core!$K29*core!$N$2/core!$N$3*core!$F$29+core!$K29*core!$N$2/core!$N$3*core!$g$29;IF(core!$H29="EURO";core!$K29+core!$K29*core!$F29+core!$K29*core!$g29;"")))))))))));
IF(core!$D$11=3;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;IF(core!$H29="USD";core!$M29*core!$N$2+core!$M29*core!$N$2*core!$F29+core!$M29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$M29*core!$N$3+core!$M29*core!$N$3*core!$F29+core!$M29*core!$N$3*core!$g29;"")));
IF(core!$D$11=3;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$M29/core!$N$2+core!$M29/core!$N$2*core!$F29+core!$M29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;IF(core!$H29="EURO";core!$M29*core!$N$3/core!$N$2+core!$M29*core!$N$3/core!$N$2*core!$F29+core!$M29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=3;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$M29/core!$N$3+core!$M29/core!$N$3*core!$F29+core!$M29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$M29*core!$N$2/core!$N$3+core!$M29*core!$N$2/core!$N$3*core!$F29+core!$M29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$M29+core!$M29*core!$F29+core!$M29*core!$g29;"")))))))))));
IF(core!$D$11=4;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;IF(core!$H29="USD";core!$O29*core!$N$2+core!$O29*core!$N$2*core!$F29+core!$O29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$O29*core!$N$3+core!$O29*core!$N$3*core!$F29+core!$O29*core!$N$3*core!$g29;"")));
IF(core!$D$11=4;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$O29/core!$N$2+core!$O29/core!$N$2*core!$F29+core!$O29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;IF(core!$H29="EURO";core!$O29*core!$N$3/core!$N$2+core!$O29*core!$N$3/core!$N$2*core!$F29+core!$O29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=4;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$O29/core!$N$3+core!$O29/core!$N$3*core!$F29+core!$O29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$O29*core!$N$2/core!$N$3+core!$O29*core!$N$2/core!$N$3*core!$F29+core!$O29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$O29+core!$O29*core!$F29+core!$O29*core!$g29;"")))))))))));
IF(core!$D$11=5;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;IF(core!$H29="USD";core!$Q29*core!$N$2+core!$Q29*core!$N$2*core!$F29+core!$Q29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$Q29*core!$N$3+core!$Q29*core!$N$3*core!$F29+core!$Q29*core!$N$3*core!$g29;"")));
IF(core!$D$11=5;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$Q29/core!$N$2+core!$Q29/core!$N$2*core!$F29+core!$Q29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;IF(core!$H29="EURO";core!$Q29*core!$N$3/core!$N$2+core!$Q29*core!$N$3/core!$N$2*core!$F29+core!$Q29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=5;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$Q29/core!$N$3+core!$Q29/core!$N$3*core!$F29+core!$Q29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$Q29*core!$N$2/core!$N$3+core!$Q29*core!$N$2/core!$N$3*core!$F29+core!$Q29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$Q29+core!$Q29*core!$F29+core!$Q29*core!$g29;"")))))))))));
IF(core!$D$11=6;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;IF(core!$H29="USD";core!$S29*core!$N$2+core!$S29*core!$N$2*core!$F29+core!$S29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$S29*core!$N$3+core!$S29*core!$N$3*core!$F29+core!$S29*core!$N$3*core!$g29;"")));
IF(core!$D$11=6;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$S29/core!$N$2+core!$S29/core!$N$2*core!$F29+core!$S29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;IF(core!$H29="EURO";core!$S29*core!$N$3/core!$N$2+core!$S29*core!$N$3/core!$N$2*core!$F29+core!$S29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=6;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$S29/core!$N$3+core!$S29/core!$N$3*core!$F29+core!$S29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$S29*core!$N$2/core!$N$3+core!$S29*core!$N$2/core!$N$3*core!$F29+core!$S29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$S29+core!$S29*core!$F29+core!$S29*core!$g29;"")))))))))));
IF(core!$D$11=7;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;IF(core!$H29="USD";core!$U29*core!$N$2+core!$U29*core!$N$2*core!$F29+core!$U29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$U29*core!$N$3+core!$U29*core!$N$3*core!$F29+core!$U29*core!$N$3*core!$g29;"")));
IF(core!$D$11=7;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$U29/core!$N$2+core!$U29/core!$N$2*core!$F29+core!$U29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;IF(core!$H29="EURO";core!$U29*core!$N$3/core!$N$2+core!$U29*core!$N$3/core!$N$2*core!$F29+core!$U29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=7;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$U29/core!$N$3+core!$U29/core!$N$3*core!$F29+core!$U29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$U29*core!$N$2/core!$N$3+core!$U29*core!$N$2/core!$N$3*core!$F29+core!$U29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$U29+core!$U29*core!$F29+core!$U29*core!$g29;"")))))))))));
IF(core!$D$11=8;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$W29+core!$W29*core!$F29++core!$W29*core!$g29;IF(core!$H29="USD";core!$W29*core!$N$2+core!$W29*core!$N$2*core!$F29+core!$W29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$W29*core!$N$3+core!$W29*core!$N$3*core!$F29+core!$W29*core!$N$3*core!$g29;"")));
IF(core!$D$11=8;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$W29/core!$N$2+core!$W29/core!$N$2*core!$F29+core!$W29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$W29+core!$W29*core!$F29+core!$W29*core!$g29;IF(core!$H29="EURO";core!$W29*core!$N$3/core!$N$2+core!$W29*core!$N$3/core!$N$2*core!$F29+core!$W29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=8;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$W29/core!$N$3+core!$W29/core!$N$3*core!$F29+core!$W29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$W29*core!$N$2/core!$N$3+core!$W29*core!$N$2/core!$N$3*core!$F29+core!$W29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$W29+core!$W29*core!$F29+core!$W29*core!$g29;"")))))))))));
IF(core!$D$11=9;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;IF(core!$H29="USD";core!$Y29*core!$N$2+core!$Y29*core!$N$2*core!$F29+core!$Y29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$Y29*core!$N$3+core!$Y29*core!$N$3*core!$F29+core!$Y29*core!$N$3*core!$g29;"")));
IF(core!$D$11=9;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$Y29/core!$N$2+core!$Y29/core!$N$2*core!$F29+core!$Y29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;IF(core!$H29="EURO";core!$Y29*core!$N$3/core!$N$2+core!$Y29*core!$N$3/core!$N$2*core!$F29+core!$Y29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=9;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$Y29/core!$N$3+core!$Y29/core!$N$3*core!$F29+core!$Y29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$Y29*core!$N$2/core!$N$3+core!$Y29*core!$N$2/core!$N$3*core!$F29+core!$Y29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$Y29+core!$Y29*core!$F29+core!$Y29*core!$g29;"")))))))))));
IF(core!$D$11=10;IF($F15>0;
IF(core!$D$7="TL";IF(core!$H29="TL";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;IF(core!$H29="USD";core!$AA29*core!$N$2+core!$AA29*core!$N$2*core!$F29+core!$AA29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$AA29*core!$N$3+core!$AA29*core!$N$3*core!$F29+core!$AA29*core!$N$3*core!$g29;"")));
IF(core!$D$11=10;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$AA29/core!$N$2+core!$AA29/core!$N$2*core!$F29+core!$AA29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;IF(core!$H29="EURO";core!$AA29*core!$N$3/core!$N$2+core!$AA29*core!$N$3/core!$N$2*core!$F29+core!$AA29*core!$N$3/core!$N$2*core!$g29;"")));
IF(core!$D$11=10;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";core!$AA29/core!$N$3+core!$AA29/core!$N$3*core!$F29+core!$AA29/core!$N$3*core!$g29;IF(core!$H29="USD";core!$AA29*core!$N$2/core!$N$3+core!$AA29*core!$N$2/core!$N$3*core!$F29+core!$AA29*core!$N$2/core!$N$3*core!$g29;IF(core!$H29="EURO";core!$AA29+core!$AA29*core!$F29+core!$AA29*core!$g29;""))))))))))))))))))))
*(core!$G29+1))
enter image description here
The IFERROR has the format IFERROR(Value, Value_if_error). Your Value is this:
IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="TL";IF(core!$H29="TL";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="USD";core!$I29*core!$N$2+core!$I29*core!$N$2*core!$F29+core!$I29*core!$N$2*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3+core!$I29*core!$N$3*core!$F29+core!$I29*core!$N$3*core!$g29;"")));IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="USD";IF(core!$H29="TL";core!$I29/core!$N$2+core!$I29/core!$N$2*core!$F29+core!$I29/core!$N$2*core!$g29;IF(core!$H29="USD";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;IF(core!$H29="EURO";core!$I29*core!$N$3/core!$N$2+core!$I29*core!$N$3/core!$N$2*core!$F29+core!$I29*core!$N$3/core!$N$2*core!$g29;"")));IF(core!$D$11=1;IF($F15>0;IF(core!$D$7="EURO";IF(core!$H29="TL";(core!$I29/core!$N$3+core!$I29/core!$N$3*core!$F29+core!$I29/core!$N$3*core!$g29);IF(core!$H29="USD";(core!$I29*core!$N$2/core!$N$3+core!$I29*core!$N$2/core!$N$3*core!$F29+core!$I29*core!$N$2/core!$N$3*core!$g29);IF(core!$H29="EURO";core!$I29+core!$I29*core!$F29+core!$I29*core!$g29;""))))))))))));
Taking your formula, splitting out the first part of the IFERROR, and eliminating the spurious code (i.e. IF(A=1, IF(B=2, IF(A=1, ALWAYS_TRUE, ALWAYS_FALSE), C), D) is functionally identical to IF(A=1, IF(B=2, ALWAYS_TRUE, C), D)), I then built the following table:
The Red, Blue and Green text are Common Terms, present in every formula.
Examining this, and rearranging it slightly, I spot the following patterns:
When D7 is "USD", Divide by $N$2
When D7 is "EURO", Divide by $N$3
When H29 is "USD", Multiply by $N$2
When H29 is "EURO", Multiply by $N$3
Implicitly, the following rules also exist:
When D7 is "TL", Divide by 1
When H29 is "TL", Multiply by 1
I can use a VLOOKUP to pick which cells to use, resulting in the form VLOOKUP(H29,..) * (Common_Terms) / VLOOKUP(D7,..)
This allows me to rewrite your Value as follows:
IF(AND(core!$D$11=1,$F15>0), IF(AND(MATCH(core!$D$11,{"TL","USD","EURO","*"},0)<4, MATCH(core!$H$29,{"TL","USD","EURO","*"},0)<4), VLOOKUP(core!H$29,{"USD",core!$N$2;"Euro",core!$N$3;"TL",1},2,FALSE)*(core!$I29 + core!$I29*core!$F29 + core!$I29*core!$g29)/VLOOKUP(core!H$29,{"USD",core!$N$2;"Euro",core!$N$3;"TL",1},2,FALSE), ""), FALSE)
Which is a third of the length. You should be able to manage similar optimisation of almost every IF condition you have.
More importantly, a lot of your repeated (and unnecessary) IF conditions are checking if H29 and D7 are "TL"/"USD"/"EUR", or checking that F15>0. You can eliminate these by making your outermost IF statement look like this:
=IF(AND($F15>0, MATCH(core!$D$7, core!$D$11, {"TL","USD","EURO","*"},0)<4, MATCH(core!$H$29, {"TL","USD","EURO","*"},0)<4), ALL_THREE_CONTITIONS_ARE_TRUE, "")
Related
I am writing a series of queries to my workbook's data model to retrieve the number of documents by Category_Name which are greater than a certain numbers of days old (e.g. >=650).
Currently this formula (entered in celll C3) returns the correct number for a single Days Old value (=3).
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]",
"[EDD_Report_10-01-18].[Days Old].[34]")
How do I return the number of documents for Days Old values >=650?
The worksheet looks like:
A B C
1 Date PL Count of Docs
2 10/1/2018 ALD 3
3 ...
UPDATE: As suggested in #ama 's answer below, the expression in step B did not work.
However, I created a subset of the Days Old values using
=CUBESET("ThisWorkbookDataModel",
"{[EDD_Report_10-01-18].[Days Old].[all].[650]:[EDD_Report_10-01-18].[Days Old].[All].[3647]}")
The cell containing this cubeset is referenced as the third Member_expression of the original CUBEVALUE formula. The limitation is now that the values for the beginning and end must be members of the Days Old set.
This is limiting, in that, I was hoping for a more general test for >=650 and there is no way to guarantee that specific values of Days Old will be in the query.
First time I hear about CUBE, so you got me curious and I did some digging. Definitely not an expert, but here is what I found:
MDX language should allow you to provide value ranges in the form of {[Table].[Field].[All].[LowerBound]:[Table].[Field].[All].[UpperBound]}.
A. Get the total number of entries:
D3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All]")
B. Get the number of entries less than 650:
E3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[0]:[EDD_Report_10-01-18].[Days Old].[All].[649]}")
Note I found something about using .[All].[650].lag(1)} but I think for it to work properly your data might need to be sorted?
C. Substract
C3 =D3-E3
Alternatively, go for the quick and dirty:
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[650]:[EDD_Report_10-01-18].[Days Old].[All].[99999]}")
Hope this helps and do let me know, I am still curious!
I've structured a formula that should spit out a numerical answer that is basically a simple sum formula with IF statements assigning numerical values to qualitative inputs. Apologies for the length, I am looking at a number of different factors.Formula is:
Cell F36 contains:
=IF(F32="Medium-High", 18, IF(F32="High", 24, SUM(F16, IF(F20="High",5,IF(F20="Medium-High",4,IF(F20="Medium",3,IF(F20="Low-medium",2,IF(F20="Low",1))))),IF(F24="High",5,IF(F24="Medium-High",4,IF(F24="Medium",3,IF(F24="Low-Medium",2,IF(F24="Low",1))))),IF(F28="High",5,IF(F28="Medium-High",4,IF(F28="Medium",3,IF(F28="Low-Medium",2,IF(F28="Low",1,IF(F28="N/A",0)))))),IF(F30="N/A",0,IF(F30="High",5,IF(F30="Medium-High",4,IF(F30="Medium",3,IF(F30="Low-Medium",2,IF(F30="Low",1)))))),IF(F32="High",5,IF(F32="Medium-High",4,IF(F32="Medium",3,IF(F32="Low-Medium",2,IF(F32="Low",1,IF(F32="N/A",0)))))))))
F16 - contains values from 1 to 5
F20, F24, F28, F30, F32 - Are dropdowns, where you choose a value: Low, Low-Medium, Medium, Medium-High, High;
Right now, based on a test input, where: F16 = 5, F20 = Low (1), F24= Medium-High (4), F28 = N/A (0), F30 = Medium (3), F32 = Medium (3) my output in F36 is 11, however doing simple adding, I should be at 5+1+4+0+3+3 = 16.
Where am I losing 5 points?
You can create a table allocating numerical output to each qualitative inputs and using vlookup to get your output. For example, for a table created on K19:L25, the following can be used:
=SUM(F16,VLOOKUP(F20,K19:L25,2,FALSE),VLOOKUP(F24,K19:L25,2,FALSE),VLOOKUP(F28,K19:L25,2,FALSE),VLOOKUP(F30,K19:L25,2,FALSE),VLOOKUP(F32,K19:L25,2,FALSE))
EDIT:
Tried your formula and it gives the correct result. Maybe your 5 in F16 is not a numerical value? You can test it by using
=ISNUMBER(F16)
and it should give a TRUE if it is a number.
Debug embedded IFs is just hell.
What you are doing is recode a 5 levels scale. You may use alternative solutions.
a. place the 5 text values (from "Low" to "High") somewhere in a sheet, say in T1:T5, even better, give this range a name
then you can retrieve the values you search with
MATCH(F20,$T$1:$T$5,0)
b. if it's suitable for your use, you may use combo boxes, presenting the 5 choices and giving the desired answer (from 1 to 5) in a linked cell.
(maybe not the answer, but I can't comment…)
(This should be a comment but I needed the formatting capabilities of an answer)
This is the current logic of your formula:
Check cell F32: "Medium-High" outputs 18, "High" outputs 24
If F32 is neither of those, then SUM the following:
F16
Lookup for F20, F24, F28, F30, and F32 where the lookup for each is:
"High" = 5
"Medium-High" = 4
"Medium" = 3
"Low-Medium" = 2
"Low" = 1
I find it strange that you first check cell F32 only to check it again later in the sum. Because this current logic produces incorrect results, we can't really advise how to fix it without sample data and expected results. My guess is you are summing too many lookups by including the F32 in there, but that's just speculation without data.
Say I have columns
/670 - White | /650 - black | /680 - Red | /800 - Whitest
These have data in their rows. Basically, I want to SUM their values together if their headers contain my desired string.
For modularity's sake, I wanted to merely specify to sum /670, /650, and /680 without having to mention the rest of the header text.
So, something like =SUMIF(a1:c1; "/NUM & /NUM & /NUM"; a2:c2)
That doesn't work, and honestly I don't know what i should be looking for.
Additional stuff:
I'm trying to think of the answer myself, is it possible to mention the header text as condition for ifs? Like: if A2="/650 - Black" then proceed to sum the next header. Is this possible?
Possibility it would not involve VBA, a draggable formula would be preferable!
At this point, I may as well request a version which handles the complete header name rather than just a part of it as I believe it to be difficult for formula code alone.
Thanks for having a look!
Let me know if I need to elaborate.
EDIT: In regards to data samples, any positive number will do actually, damn shame stack overflow doesn't support table markdown. Anyway, for example then..:
+-------------+-------------+-------------+-------------+-------------+
| A | B | C | D | E |
+---+-------------+-------------+-------------+-------------+-------------+
| 1 |/650 - Black |/670 - White |/800 - White |/680 - Red |/650 - Black |
+---+-------------+-------------+-------------+-------------+-------------+
| 2 | 250 | 400 | 100 | 300 | 125 |
+---+-------------+-------------+-------------+-------------+-------------+
I should have clarified:
The number range for these headers would go from /100 - /9999 and no more than that.
EDIT:
Progress so far:
https://docs.google.com/spreadsheets/d/1GiJKFcPWzG5bDsNt93eG7WS_M5uuVk9cvkt2VGSbpxY/edit?usp=sharing
Formula:
=SUMPRODUCT((A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($H$1)=4,$H$1&"",$H$1&" ")))+(A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($I$1)=4,$I$1&"",$I$1&" ")))+(A2:D2*
(MID($A$1:$D$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" "))))
Apparently, each MID function is returning false with each F9 calculation.
EDIT EDIT:
Okay! I found my issue, it's the /being read when you ALSO mentioned that it wasn't required. Man, I should stop skimming!
Final Edit:
=SUMPRODUCT((RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match5)=4,Match5&"",Match5&" ")))+(RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match6)=4,Match6&"",Match6&" ")))+(RETURNSUM*
(MID(HEADER,2,4)=IF(LEN(Match7)=4,Match7&"",Match7&" ")))
The idea is that Header and RETURNSUM will become match criteria like the matches written above, that way it would be easier to punch new criterion into the search table. As of the moment, it doesn't support multiple rows/dragging.
I have knocked up a couple of formulas that will achieve what you are looking for. For ease I have made the search input require the number only as pressing / does not automatically type into the formula bar. I apologise for the length of the answer, I got a little carried away with the explanation.
I have set this up for 3 criteria located in J1, K1 and L1.
Here is the output I achieved:
Formula 1 - SUMPRODUCT():
=SUMPRODUCT((A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" ")))+(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($K$1)=4,$K$1&"",$K$1&" ")))+(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($L$1)=4,$L$1&"",$L$1&" "))))
Sumproduct(array1,[array2]) behaves as an array formula without needed to be entered as one. Array formulas break down ranges and calculate them cell by cell (in this example we are using single rows so the formula will assess columns seperately).
(A4:G4*(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" ")))
Essentially I have broken the Sumproduct() formula into 3 identical parts - 1 for each search condition. (A4:G4*: Now, as the formula behaves like an array, we will multiply each individual cell by either 1 or 0 and add the results together.
1 is produced when the next part of the formula is true and 0 for when it is false (default numeric values for TRUE/FALSE).
(MID($A$1:$G$1,2,4)=IF(LEN($J$1)=4,$J$1&"",$J$1&" "))
MID(text,start_num,num_chars) is being used here to assess the 4 digits after the "/" and see whether they match with the number in the 3 cells that we are searching from (in this case the first one: J1). Again, as SUMPRODUCT() works very much like an array formula, each cell in the range will be assessed individually.
I have then used the IF(logical_test,[value_if_true],[value_if_false]) to check the length of the number that I am searching. As we are searching for a 4 digit text string, if the number is 4 digits then add nothing ("") to force it to a text string and if it is not (as it will have to be 3 digits) add 1 space to the end (" ") again forcing it to become a text string.
The formula will then perform the calculation like so:
The MID() formula produces the array: {"650 ","670 ","800 ","680 ","977 ","9999","143 "}. This combined with the first search produces {TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE} which when multiplied by A4:G4
(remember 0 for false and 1 for true) produces this array: {250,0,0,0,0,0,0} essentially pulling the desired result ready to be summed together.
Formula 2: =SUM(IF(Array)): [This formula does not work for 3 digit numbers as they will exist within the 4 digit numbers! I have included it for educational purposes only]
=SUM(IF(ISNUMBER(SEARCH($J$1,$A$1:$G$1)),A8:G8),IF(ISNUMBER(SEARCH($K$1,$A$1:$G$1)),A8:G8),IF(ISNUMBER(SEARCH($L$1,$A$1:$G$1)),A8:G8))
The formula will need to be entered as an array (once copy and pasted while still in the formula bar hit CTRL+SHIFT+ENTER)
This formula works in a similar way, SUM() will add together the array values produced where IF(ISNUMBER(SEARCH() columns match the result column.
SEARCH() will return a number when it finds the exact characters in a cell which represents it's position in number of characters. By using ISNUMBER() I am avoiding having to do the whole MID() and IF(LEN()=4,""," ") I used in the previous formula as TRUE/FALSE will be produced when a match is found regardless of it's position or cell formatting.
As previously mentioned, this poses a problem as 999 can be found within 9999 etc.
The resulting array for the first part is: {250,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE} (if you would like to see the array you can highlight that part of the formula and calculate with F9 but be sure to highlight the exact brackets for that part of the formula).
I hope I have explained this well, feel free to ask any questions about stuff that you don't understand. It is good to see people keen to learn and not just fishing for a fast answer. I would be more than happy to help and explain in more depth.
I start this solution with the names in an array, you can read the header names into an array with not too much difficulty.
Sub test()
Dim myArray(1 To 4) As String
myArray(1) = "/670 - White"
myArray(2) = "/650 - black"
myArray(3) = "/680 - Red"
myArray(4) = "/800 - Whitest"
For Each ArrayValue In myArray
'Find position of last character
endposition = InStr(1, ArrayValue, " - ", vbTextCompare)
'Grab the number section from the string, based on starting and ending positions
stringvalue = Mid(ArrayValue, 2, endposition - 2)
'Convert to number
NumberValue = CLng(stringvalue)
'Add to total
Total = Total + NumberValue
Next ArrayValue
'Print total
Debug.Print Total
End Sub
This will print the answer to the debug window.
This question relates to the Schematiq add-in for Microsoft Excel.
Using =tbl.Lookup(table, columnsToSearch, valuesToFind, resultColumn, [defaultValue]) the values in the valuesToFind column have a consistent 3 characters to the left and then varying characters after (e.g. 908-123456 or 908-321654 - i.e. 908 is always consistent)
How can I tell the function to lookup the value based on the first 3 characters only? The expected answer should be the sum of the results of the above, i.e. 500 + 300 = 800
tbl.Lookup() works by looking for an exact match - this helps ensure it's fast but in this case it means you need an extra step to calculate a column of lookup values, something like this:
A2: =tbl.CalculateColumn(A1, "code", "x => LEFT(x, 3)", "startOfCode")
This will give you a new column that you can use for the columnsToSearch argument, however tbl.Lookup() also looks for just one match - it doesn't know how to combine values together if there is more than one matching row in the table, so I think you also need one more step to group your table by the first 3 chars of the code, like this:
A3: =tbl.Group(A2, "startOfCode", "amount")
Because tbl.Group() adds values together by default, this will give you a table with a row for each distinct value of startOfCode and the subtotal of amount for each of those values. Finally, you can do the lookup exactly as you requested, which for your input table will return 800:
A4: =tbl.Lookup(A3, "startOfCode", "908", "amount")
Working with 2 separate data sets (with duplicates)
Dataset is unique identified by an ID.
There may not be an entry for the timestamp I require.
Datasets are quite large, and due to duplicates, can't use vlookup.
Samples:
Table 1:
Device Name|Time Bracket| On/Off?
ID1 |06:20:00 |
ID2 |06:20:00 |
ID3 |06:30:00 |
Table 2:
Device Name |Timestamp |On/Off?
ID1 |06:20:00 |On
ID2 |06:50:00 |Off
ID3 |07:20:00 |Off
What I want to achieve:
I want an if statement to check if:
1) device ID matches AND
2) timestamp matches
If so, return the value of On/Off from Table 2.
If not, then I want it to return the value of the cell above it IF it's the same device, otherwise just put "absent" into the cell.
I thought I could do this with some IF statements like so:
=if(HOUR([#[Time Bracket]]) = HOUR(Table13[#[Timestamp Rounded (GMT)]]) and
minute([#[Time Bracket]]) = minute(Table13[#[Timestamp Rounded (GMT)]]) and
[#[Device Name]]=Table13[#[Device Name]], Table13[#[On/Off?]],
IF([#[Device Name]]=Table13[#[Device Name]], INDIRECT("B" and Rows()-1), "absent"))
(I put some newlines in there for readability)
However, this doesn't seem to resolve at all... what am I doing wrong?
Is this even the correct way of achieving this?
I've also tried something similar with a VLookUp, but that failed horribly.
Thanks all!
To not deal with array formulas or merging strings which, (not in your case) can still be wrong at the end, I suggest the use of COUNTIFS due to the fact, you have a very small amount of outcomes (just on or off)...
for the first table (starting at A1, so the formula is at C2):
=IFERROR(CHOOSE(
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"))+
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"))*2
,"On","Off","Error"),IF(A1=[#[Device Name]],C1,"Absent"))
this will also show "Error" of a match for "On" and "Off" is shown... to skip that and increase the speed, you also could use:
=IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"),"On",
IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"),"Off",
IF(A1=[#[Device Name]],C1,"Absent")))
For both the "Device Name" is at column A, "Time Bracket" at column B and "On/Off?" at column C while the table starts at row 1... If that is not the case for you, then change A1 and C1 so they match
(Also inserted line-breaks for better reading)
Picture to show the layout:
I picked the second formula to show how it works... also, this formula should not be able to return 0's... I'm confused
Couple of good suggestions, however using the helper column as suggested in the topic by Scott Craner above worked.
Created a helper column of concat'd device ID and timestamp for both tables, then did a simple VlookUp.
Another lesson learned: Think outside of the box, and go with simple solutions, rather than try + be too clever like I was doing... :)