Subtracting from total if adjacent cell has content - if-statement

I'm looking to subtract from a total derived from the following:
Count the occurrences of the content in cell E2 =COUNTIF(B:B, E2)
I want to subtract 1 from that total IF an adjacent cell contains anything.
FOr example:
B2 has content == E2, and C2 is NOT empty, subtract 1 from total
B3 has content == E2, and C3 is empty
B4 has content == E2, and C4 is NOT empty, subtract 1 from total
The end result would be =COUNTIF(B:B, E2)-2.
This seemed kind of ridiculous to explain in text so here is an example worksheet with a column expressing where I would like to see the formula, and a column with the expected output. Programatically this would be a very simple task, but doing it in a spreadsheet is new to me. I'm hoping this can be done.
https://docs.google.com/spreadsheets/d/15xEEyeJx1atsZiDDwCk57KfnbCcZbIavV-gyVF0xuCA/edit?usp=sharing
Also, column A and B can vary in length, so I would prefer something that adapts to the length of the column.

delete range D:F
use in D2:
=ARRAYFORMULA(QUERY(QUERY({B1:B,
IF((B1:B<>C1:C)*(A1:A<>"")*(C1:C=""), 1, 0)},
"select Col1,count(Col1),sum(Col2)
where Col1 !=''
group by Col1"),
"offset 1", 0))

Related

SUMIFS ARRAYFORMULA returns blank cell if the value is 0, how do I force it to show 0

Here's my formula for the cell K37:
=IFERROR(1/(1/ArrayFormula(sumifs($H37:$H,$E37:$E,"ABC",MONTH($G37:$G),1))))
the cell K37 returns nothing (it's blank) when there's no cells in $E37:$E range with the "ABC" criteria and some value in corresponding $H37:$H range's cell. And it's fine!
But how do I force the formula to return 0 instead of just a blank cell if there's at least one cell in $E37:$E range, satisfying the "ABC" criteria with the actual $0.00 value in corresponding $H37:$H range's cell?
                 E           G            H           K 
37          ABC       Jan-1     $0.00      blank (but I want it to be 0)
38
39
A way:
K37
=ARRAYFORMULA(IF(COUNTIFS($E37:$E,"ABC",MONTH($G37:$G),1),IFERROR(1/(1/SUMIFS($H37:$H,$E37:$E,"ABC",MONTH($G37:$G),1)),0),""))
Check if value exists, if #DIV/0! return 0, otherwise return blank.

How to forecast the column value based on its previous value in Python

I have a dataframe with 3,000,000 IDs. Each ID has the month range from 2015-01-01
t0 2018-12-01. Each ID has column "A" and "B" with numeric values. I need to create a new column "C:.
For each ID, when Date == '2015-01-01' which is the first month for that ID, column C value equal to exp(column_A value).
For the next month (Date == '2015-02-01'), column C value equal to exp(log(column_C_value in previous month) + column_B_value at this month), so here is exp(log(column C # 2015-01-01) + column_B # 2015-02-01). Each of the following months has the same pattern until it reaches 2018-12-01.
In Python, I can setup the loop for each ID and for each row/month, such as:
for ID in range(xxx):
for month in range(xxxx):
However, such calculation takes long time. Can anyone tell me a faster way to do this calculation? Very appreciated for your help!
Consider that
(1) exp(x+y) == exp(x)*exp(y).
And
(2) exp(log(x)) == x.
So exp(log(c1) + b2) == c1 * exp(b2).
The next value simplifies to c1 * exp(b2) * exp(b3), and so on.
That means, you have to multiply all exp(b) values, which can be turned
into adding all(b)-s and then applying exp() to the result.
And don't forget to multiply it with a1, the initial value.
a1 * exp(b2 * b3 * ...)

Subtracting value over multiple cells

I am trying to build a spreadsheet that keeps track of my inventory. I want to use the First In First Out approach and need the formula to solve the following problem. I want to subtract the value 16 from the list of stocks over multiple rows.
Value= 16
Column A --> Column B
10 0
5 0
2 1
3 3
12 12
delete everything in B column and use this ArrayFormula like:
=ARRAYFORMULA(
IF(IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1})>A4:A, 0,
IF(IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1})>0, A4:A-
IF(A4:A="", ,{B1; (SUMIF(ROW(A4:A), "<="&ROW(A4:A), A4:A)-B1)*-1}), A4:A)))
Sample below:
Subtract: B2 = number [16]
Subtract: B3 = formula =B2-A2. Copy down.
Out: C2 = formula =IF(B2>A2,0,IF(B2>0,A2-B2,A2)). Copy down.

A cell containing a range of values and making calculations with that range

Is it possible to have a range of values in a cell so that Sheets understands it when calculating something?
Here's an example of the desired output:
A B C
1 Value Share Total sum
2 100.00 90-110% 90-110
Here, Total sum (C2) = A2 * B2 (so 100 * 90-110%), giving a range of 90-110.
However, I don't know how to insert this range of values into a cell without Sheets saying #VALUE!.
you will need to do it like this:
=REGEXREPLACE((A2*REGEXEXTRACT(B2, "\d+")%)&"-"&
A2*REGEXEXTRACT(B2, "-(\d+%)"), "\.$", )
for decimals:
=REGEXREPLACE((A40*REGEXEXTRACT(B40, "\d+.\d+|\d+")%)&"-"&
A40*REGEXEXTRACT(B40, "-(\d+.\d+%)|-(\d+%)"), "\.$", )

Aspose Cell Java - Splitting Cell Horizontally

How do i fit values in those horizontally splitted cells ? I am cloning each row dynamically. The values being populated currently is a merge field as i was using this approach but i couldn't make the report dynamic with it.
Any help would be appreciated.
Well, you cannot input two values in a single cell in MS Excel. I think You may achieve your task by merging/ un-merging some cells and input values into relevant cells accordingly. See the sample code below for your reference, it covers and design some part of your attached table/matrix. Please refer to it and you may write your own code (via Aspose.Cells APIs) to accomplish your task accordingly:
var workbook = new Workbook();
var worksheet = workbook.Worksheets[0];
//Input header value to B1 cell (later we will merge it: B1:C1 --> B1
worksheet.Cells[0, 1].PutValue("header2");
//Input value to B2 cell that would be merged with B3 to become B2.
worksheet.Cells[1, 1].PutValue(1);
//Input value to C2 cell.
worksheet.Cells[1, 2].PutValue(2);
//Input value to C3 cell.
worksheet.Cells[2, 2].PutValue(3);
//Set row heights for 2nd and third rows for the cells accordingly.
worksheet.Cells.SetRowHeight(1, 25);
worksheet.Cells.SetRowHeight(2, 25);
//Merging cells.
//Merge B1:C1 --> B1
worksheet.Cells.Merge(0, 1, 1, 2);
//Merge B2:B3 --> B2
worksheet.Cells.Merge(1, 1, 2, 1);
//Formatting cells and ranges.
//Creating a range that spans over the all data cells of a worksheet
var range = worksheet.Cells.CreateRange("B1", "C3");
//Create a Style object.
Style colstyle = workbook.CreateStyle();
colstyle.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
colstyle.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
colstyle.HorizontalAlignment = TextAlignmentType.Center;
StyleFlag flag = new StyleFlag();
flag.Borders = true;
flag.HorizontalAlignment = true;
//Apply the style to the range
range.ApplyStyle(colstyle, flag);
workbook.Save("e:\\test2\\output__mergedcells.xlsx");
See the screen shot of the output Excel file taken in Ms Excel for your reference:
http://prntscr.com/8rbc0i
I am a developer/evangelist at Aspose.