Add up the number of consecutive True/False in DolphinDB - add

As shown in the picture, the first 4 values are false and the cum value is 4. Then the fifth value is true, return 0. How to add up the number of consecutive false values?

cumPositiveStreak can add up the number of consecutive true values in a boolean vector.

Related

Is there a way to SUMIFS with multiple criteria + true or false?

I want to sum the total value with its correct corresponding criteria and if the last condition will be true or false. If true, it will proceed to the sumifs, and if false "0" value. If there is no date, the value in each column will be zero
D9=SUMIFS(STORE!$C$6:$C$1000;STORE!$A$6:$A$1000;"*"&SUMMARY!$D$5&"*";STORE!$D$6:$D$1000;"*"&SUMMARY!$C$9&"*";STORE!$E$6:$E$1000;"*"&SUMMARY!D8&"*")
The question isn't so clear. Where are the criteria column or conditions in your excel? According to your current formula, if there is no date, all values should be zero. why are you using ""& &""?
As I understood maybe you can add as the last criteria
=SUMIFS(STORE!$C$6:$C$1000;STORE!$A$6:$A$1000;""&SUMMARY!$D$5&"";STORE!$D$6:$D$1000;""&SUMMARY!$C$9&"";STORE!$E$6:$E$1000;""&SUMMARY!D8&"";STORE!$AA$6:$AA$1000;TRUE)
STORE!$AA$6:$AA$1000: False or True column

Excel: How do I return an array of values based off of duplicates in a corresponding column?

Based off of Column 1, is there an excel formula I could write in Column 3 that groups True/False (in Column 2) by duplicate letters and identifies if these letter groups contain at least one True.
Ex: Group A = {True, False, True, False} --> Contains at least one True and thus all 4 rows with Letter A have True in Column 3
*Rows in Column 1 aren't necessarily alphabetized and are listed without any particular order.
I have tried using match/index excel functions and I seem to be having trouble since match only returns the position of the first match.
I understand once I have this array of boolean values, "OR" can be used to determine Column 3 simply.
Thanks for your help.
Just use COUNTIFS:
=COUNTIFS(A:A,A1,B:B,TRUE)>0

How to find first non zero value in a column?

in column A first value is 0, second is 0, third is 17, fourth is 0 and fifth is 32
in this case , first non zero value is 17. how to calculate it by formula
In cell B1:
=INDEX(A1:A5,MATCH(TRUE,INDEX(A1:A5<>0,),0))
Explanation for the above formula:
The inner Index function evaluates the values in the A1:A5 range to either TRUE or FALSE based on the specified condition, that is, not equal to 0. So 17 and 32 evaluate to TRUE, everything else to FALSE. The Match function returns the row number where the first instance of the specified condition TRUE is. This occurs on the 3rd row of the range, so Match evaluates to 3. Finally, the outer Index functions returns the value at row number 3 in the specified A1:A5 range, which is 17.

Sumproduct Excel one condition two columns to multiply and add

I am trying to use excel to calculate how much of a number of components from bills of materials (BOMs) are used per month.
So I have several columns of components but a component can appear in several columns. Offset from these columns is the quantity of that component in the BOM and in another column are the sale quantities. Is SUMPRODUCT the correct formula to use?
I have tried:
=sum(sumproduct((B2:B10="Component1")*(L2:L10)*(AH2:AH10)), sumproduct((C2:C10="Component1")*(M2:M10)*(AH2:AH10)))
B and C columns contain the component codes, L and M the component quantity per BOM and AH the sales quantity.
What am i doing wrong? Will this work? The quantities this returns are not correct.
Thanks,
In SUMPRODUCT, you should use comma or semicolon depending on your locale to separate the arrays being multiplied instead of using multiplication operator (*).
=SUM(SUMPRODUCT(--($B$2:$B$10="Component1"),$M$2:$M$10,$AH$2:$AH$10),SUMPRODUCT(--($B$2:$B$10="Component1"),$L$2:$L$10,$AH$2:$AH$10))
Since ($B$2:$B$10="Component1") evaluates to an array of TRUE & FALSE, you use -- to convert that to 1 or 0. You can also multiply it by 1.
=SUM(SUMPRODUCT(1*($B$2:$B$10="Component1"),$M$2:$M$10,$AH$2:$AH$10),SUMPRODUCT(1*($B$2:$B$10="Component1"),$L$2:$L$10,$AH$2:$AH$10))
SUMPRODUCT treats array entries that are not numeric as if they were zeros. The first parameter in each of your sumproducts will evaluate to either TRUE or FALSE but they are not strictly numeric. You can coerce them to numbers - TRUE = 1, FALSE = 0 by:
Multiplying by double negative
Multiplying by 1 or
Adding 0
So change your formula to:
=SUM(SUMPRODUCT(--(B2:B10="Component1")*(L2:L10)*(AH2:AH10)),
SUMPRODUCT(--(C2:C10="Component1")*(M2:M10)*(AH2:AH10)))

Find zero after peak

I'm working with data sets that increase until they hit a peak and then quickly drop to zero; I want to find the location of that first zero after the peak as that will give me the failure time. However, the values leading up to the peak sometimes contain zero, and my current formula is returning the times for those. An example value set would be either something like [1;1;2;6;7;10;9;0;0;0] or something like [-1;-1;0;4;7;11;10;0;0;0].
We'll say the Time column is A and the Values column is B. I've calculated the minimum value after the peak with:
=MIN(OFFSET(B1,MATCH(MAX(B2:B4001),B:B,0),0,(4001-MATCH(MAX(B2:B4001),B:B,0))))
Using that as a helper cell, I'm retrieving the time at which this value occurs with:
=IF(*min_after_peak*>0,"PASS",INDEX(A:A,MATCH(*min_after_peak*,B:B,0)))
Side note - the "peak" lasts for more than one time measurement and can fluctuate slightly, so if the minimum after the peak is positive that means the sample didn't fail. The minimum after the peak is always either positive or zero (pass or fail, respectively).
Problem is, I don't know how to get MATCH to look at only values after the peak, or if that's even the right way to go.
Any thoughts on how to get the time corresponding to the first zero after the peak?
Assuming your data is in paired columns (starting in A1) please try:
=INDEX(A1:A10,MATCH(0,INDIRECT(CHAR(COLUMN()+65)&MATCH(MAX(B1:B10),B1:B10,0)&":"&CHAR(COLUMN()+65)&"10"),0)+MATCH(MAX(B1:B10),B1:B10,0)-1)
I created a spreadsheet with your first set of data.
0 ispeak peakExists peakAndZero
1 TRUE TRUE FALSE
1 FALSE TRUE FALSE
2 TRUE TRUE FALSE
6 TRUE TRUE FALSE
7 TRUE TRUE FALSE
10 TRUE TRUE FALSE
9 FALSE TRUE FALSE
0 FALSE TRUE TRUE
0 FALSE TRUE TRUE
0 FALSE TRUE TRUE
I added a 0 in a1 and headers in B1, C1, and D1.
In the first row of the isPeak column, that is B2, I added =IF(AND(A2>A1,A2>0),TRUE,FALSE). This puts a true in the cell if the value to the left (A2) is greater than the previous (A1) AND it is greater than 0.
In the first row of the peakExists column, that is C2, I added =OR($B$2:B2). This puts a true in the cell if any of the previous from b2 (absolute) to my row has even a single true.
In the first row of the peakAndZero column, that is D2, I added =AND(C2,A2=0). This puts a true in the cell if a peak exists and the value is a 0.
It looks like you know how to create the index of the row and you know how to select the lowest one with a true in peakAndZero, so I will leave this as an exercise for the OP.
Came up with an adaption to my original formula that avoids helper columns (I have several hundred data sets for this project). Used OFFSET to set an after-peak range in MATCH:
=IF(min_after_peak>0,"PASS",INDEX(A:A,MATCH(MAX(B2:B4001),B:B,0)+MATCH(min_after_peak,OFFSET(B1,MATCH(MAX(B2:B4001),B:B,0),0,(3603-MATCH(MAX(B2:B4001),B:B,0))),0)))
To make it slightly easier to read:
=IF(min_after_peak>0,"PASS",INDEX(A:A,peak_row+MATCH(min_after_peak,OFFSET(B1,peak_row,0,(4001-peak_row)),0)))
where
peak_row = MATCH(MAX(B2:B4001),B:B,0)

Resources