I want to create a calculated column "indicateur" that traces the boolean values
when I have a True, I increment the indicator by 1, however i want the false rows to have the value of the last true indicator.
and when i pass to a new ID, the incrementation starts from zero.
I already tried some spotfire expression using the over function but not getting the right results
case
when [boolean] then sum(If([boolean],1,0)) over (Intersect([ID],AllPrevious([ID])))
else 0
end
You have a couple of issues here. Your case statement is sub setting the data... it will only calculate sums where boolean is true.
The main issue is the over statement though. Something like this should give the correct answer
sum(If([boolean],1,0)) over (Intersect([ID],AllPrevious([Timestamp])))
Related
I recently got started with Excel Power Query, retrieving data from SharePoint. Things worked nicely until I noticed that some cells in a worksheet doing lookups on the query result (both in the same workbook) did not get calculated. The value just showed 0. When I selected the cell and hit enter, recalculation for the cell happened and the correct value was shown. Calculation method is "Automatic except data tables" (I hope I translated this correctly).
I traced the issue to a specific UDF I use within many of my UDFs, a function checking whether a range (or more precise a parameter) has been recalculated and if not, the outer UDF is exited immediately. This is a common recommendation found on many sites to improve performance and I never had any issues with it - until the arrival of power query, that is.
There seem to be a few possible solutions which one could pursue:
Somehow trigger a full recalculation&rebuild after a query is executed. Would require some kind of trigger or event (which I currently don't know).
Make the UDF which checks if the argument is dirty more intelligent. By the observed behavior, my takeaway is, that the table containing the query result always counts as dirty(?). If so, teaching the UDF about this, would help.
Make sure that the query results always count as clean in excel.
I would rather avoid the first solution.
The third solution sound as if it may have unwanted side effects, so my preference would be to the second venue: Improve the UDF checking if an argument is dirty.
Here it is in its current state (leading to the above described behavior):
Public Function chkRngCalculated(theParameter As Variant) As Boolean
Dim vHasFormula As Variant
chkRngCalculated = True
On Error GoTo Fail
If TypeOf theParameter Is Excel.Range Then
vHasFormula = theParameter.HasFormula
' HasFormula can be True, False or Null:
' Null if the range contains a mix of Formulas and data
If IsNull(vHasFormula) Then vHasFormula = True
If vHasFormula Then
' CountA returns 0 if any of the cells are not yet calculated
If Application.WorksheetFunction.CountA(theParameter) = 0 Then chkRngCalculated = False
End If
' a calculated parameter is Empty if it references uncalculated cells
ElseIf VarType(theParameter) = vbEmpty Then
chkRngCalculated = False
End If
Exit Function
Fail:
chkRngCalculated = False
End Function
It is usually called in one of the first lines of a UDF, never from Excel cells directly obviously. The following shows how it is called from my lookup function:
Public Function searchKeyed(target As Range, rowKey As Variant, columnKey As Variant) As Variant
If Not chkRngCalculated(target) Then Exit Function
...
I verified that, if I comment out the if statement, the values do get updated correctly upon query update.
Background updating of the queries has been turned off. Switching to 'Automatic' recalculation from 'Automatic except data tables' does not change the described behavior.
Has someone had a similar experience and found a solution?
All of the methods that I've used have 2 answer values (True or False).
How can I get the following with a formula?
If A1=1 then it's 11, if A1=2 the answer is 22, if A1=3 then it's 33, if A1=4 it's 44.
If the value your are evaluating is in cell A1, then the nested function would be as follows:
IF(A1=1,11,IF(A1=2,22,IF(A1=3,33,IF(A1=4,44,""))))
I put the 2 double commas at the end so the formula returns a blank instead of false.
I don't know if that's what you are asking about, but you can make multiple (nested) IF statements in one. For example:
IF(1=2;TRUE;IF(2=2;TRUE;FALSE))
You just put another IF in the FALSE part of IF statement. If that's not it, can you give a piece of the statement you tried and precise more what do you want?
=IF(AND(INT(A1)=A1,A1<=4,A1>=1),A1*11,"")
Now the above works for the condition you placed in your example, however if one were to go by your title alone you have a couple of options you could go with.
You first Option would be nested IF statements. Like you said each IF function has TRUE or FALSE. The trick is to put another IF function in for the TRUE result and another in for the FALSE results
IF(CHECK1, IF(CHECK2, TRUE2, FALSE2),IF(CHECK3, TRUE3, FALSE3))
The above give 4 potential results based on only 3 checks. Another option would be to do a check and supply a value for a TRUE result and another IF for a false result. Keep repeating the process. Conversely you could go the same route flipping TRUE FALSE option. It might look something like this:
IF(CHECK1, TRUE1, IF(CHECK2, TRUE2, IF(CHECK3, TRUE3, FALSE3)))
FALSE3 would be the result of all previous checks failing.
So for your case, your nested IF could look like (assuming the only valid entries are 1, 2, 3 and 4):
IF(A1=1,11,IF(A1,2,22,IF(A1=3,33,44)))
OR
IF(ISODD(A1),IF(A1=1,11,33),IF(A1=2,22,44))
and there are other options to work through the logic. there are also other checks you could be doing and results being displayed if your entries in A1 were not limited to the integers 1,2,3 and 4.
Now because you example is using the sequential integers 1,2,3 and 4 you could also use the CHOOSE function. Alternatively if you can make your criteria evaluate to sequential integers stating at 1 the CHOOSE function would work as well. Supply choose with an integer as the first argument and it will return the corresponding argument in the list that follows
CHOOSE(ARGUMENT,RESULT1, RESULT2,...,RESULTn-1, RESULTn)
In your case it would look something like:
CHOOSE(A1,11,22,33,44)
If you can not get sequential numbers for whatever reason and the gap is numbers is small and you are in the low integer count, you could leave a gap in results by providing "", or 0). lets say you has 1,3 and 4 as potential arguments, then your choose might look like:
CHOOSE(A1,11,"",33,44)
=IF(A1<>"",INDEX({11;22;33;44},A1),"")
=IF(AND(ISNUMBER(A1),A1<=4),A1*11,"")
I have this IF statement:
=IF(AG3<=7,"1",IF(15<=AG3<=21,"2",IF(22<=AG3<=28,"3",IF(29<=AG3<=35,"4",IF(36<=AG3<=42,"5",IF(43<=AG3<=49,"6",IF(50<=AG3<=56,"7")))))))
but either it gives me a 1 or "FALSE"
All the values are within the ranges and should be showing various numbers
Excel does not use 50<=AG3<=56. The way Excel will read this is it will resolve AG3<=56 which will resolve to TRUE or FALSE which have the values of 1 and 0 respectively. And since 50 is greater than both those it will always return FALSE and since you did not specify a final false argument Excel returns FALSE
It needs to be AND(50<=AG3, AG3<=56)
Also "1" returns a number as text and not a true number, remove the quotes.
So:
=IF(AG3<=7,1,IF(AND(15<=AG3,AG3<=21),2,IF(AND(22<=AG3,AG3<=28),3,IF(AND(29<=AG3,AG3<=35),4,IF(AND(36<=AG3,AG3<=42),5,IF(AND(43<=AG3,AG3<=49),6,IF(AND(50<=AG3,AG3<=56),7,"Value not in specs")))))))
But based on your criteria you could use:
=IF(OR(AND(AG3>=8,AG3<=14),AG3>56),"Not to Spec",MATCH(AG3,{-1E+99,15,22,29,36,43,40}))
Don't use Nested IFs if you can avoid it. Instead, use a banded VLOOKUP: it's many times more efficient, and a heck of a lot simpler to troubleshoot. Something like the answer here:
Excel IF statement Not returning the appropriate Value
In your case, here's your lookup list:
Note that since you haven't specified what should happen between 8 and 14 or over 57 I have simply put =NA() in those bands.
And here's the result for a range of numbers:
...and here's the formula that was used in the second column of that second table (using table notation):
=VLOOKUP([#Value],Table3,2,TRUE)
I have the following formula:
=IF(AND(A1=0,A3="","1 item"),
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items"))))
3 combinations of cell values in A1 and A3 return text which I'm calling "1 item"
Only 1 combination of cells value returns text which I'm calling "2 items".
The only combination to return "2 items" is where A1=1 AND A3="".
The formatting is wrong but I'm not sure where.
Any help would be greatly appreciated.
this is the correct formula -
brackets of AND() were not properly closed.
=IF(AND(A1=0,A3=""),"1 item",IF(AND(A1=0,A3="Exclude"),"1 item",IF(AND(A1=1,A3="Exclude"),"1 item","2 items")))
Excel's IF expects three parameters: Condition, What to do if condition is TRUE, and what to do if condition is FALSE.
I'll re-format your formula so you can see where the error is:
IF( AND(A1=0,A3="","1 item") ,
IF(AND(A1=0,A3="Exclude","1 item"),
IF(AND(A1=1,A3="Exclude","1 item","2 items")
)
)
)
As you can see
For the first IF you are not providing what to do if condition is FALSE,
The same for the second IF,
The third IF has no definition of what to do if the condition is TRUE or FALSE.
Hope this helps you.
UPDATE
Following your comment (which is still not clear to me), hereinafter I'm providing simple rules you may use to construct your formula correctly:
Write your formula as a piece of text (like the example I show above) so that you can easily read, edit and verify it,
Remember that Excel's IF has three parameters: Condition, result when condition is TRUE and result when condition is FALSE,
Within any of these three parameters, you can include whatever you want PROVIDED that the result is compliant with what the function expects for that parameter; for instance, writing for the first parameter 3=8 is completely legal since the result is FALSE (while 4=2*2 would yield TRUE).
Having this in mind, here is the formula I think you are looking for (WARNING!!! I'm not sure I understood what you need, but if not, changing it should be very easy for you now):
IF(AND(A1=1,A3=""),"2 items","1 item")
This is based on your wording: The only combination to return "2 items" is where A1=1 AND A3="".
I'm struggling to see why the below isn't working for the final statement:
=IF(ISERROR(SEARCH("Investment Commentary",E73)), IF(ISERROR(SEARCH("Quarterly Update",E73)),"Quarterly Update"),"Investment Commentary")
So in Column C is my formula, and Column E contains text I'm searching.
My original formula has 12 of these and they all work, except for the last one.
I thought perhaps I'd hit a limit, but for some reason it refuses to see the final IF statement and simply returns FALSE.
Any help would be much appreciated!
Your first IF has a TRUE and FALSE part.....but the TRUE part consists of an IF statement with no FALSE part, so if the first IF is TRUE and the second is FALSE you get FALSE, you need to put something where I've indicated:
=IF(ISERROR(SEARCH("Investment Commentary",E73)), IF(ISERROR(SEARCH("Quarterly Update",E73)),"Quarterly Update","Something Here"),"Investment Commentary")