Arrayformula with vlookup - Range Issue - arrays

I am trying to range the Data from the tab "Extracted data" in the tab "Action Items"
Conversion Potential column (Action items tab) is taking the data from CTR Delta (Extracted data tab).
Relevance column (Action items tab) is taking the data from Position Delta (Extracted data tab).
For some reasons, it simply does not range the data in the right way.
Conversion Potential Range should go like:
CTR Range
-2 1
-1 2
0 3
1 4
2 5
Relevance is expected to be ranged like:
Range Result
0-10 5
10-20 4
20-30 3
30-40 2
40-50 1
50-100 0
https://docs.google.com/spreadsheets/d/1MlyMmZ3JcWmYeDS86YB7yQnTsb7Fv0btYa7b4o-zwgo/edit#gid=1011640328

For 'Action Items'!M3 (delete cells below):
=arrayformula({"Conversion Potential";iferror(vlookup(vlookup(D4:D,'Extracted Data'!A:N,14,0),{-2,1;-1,2;0,3;1,4;2,5},2,1),)})
For 'Action Items'!N3 (delete cells below):
=arrayformula({"Relevance";iferror(vlookup(vlookup(D4:D,'Extracted Data'!A:N,13,0),{0,5;11,4;21,3;31,2;41,1;51,0},2,1),)})

Related

Sumproduct in Netezza

I want to calculate sumproduct in netezza table, where one column is fixed. In frist column (A) I have some numbers in DISCOUNT are discount factors. As a result I want to get sumproduct bewteen A and DISCOUNT, where DISCOUNT always start from first row.
Number in RESULTS:
14,54535 = 5/(1+2%)+3/(1+3%)+7/(1+4%),
9.737293 = 3/(1+2%)+7/(1+3%)
6.862745 = 7/(1+2%)
Always when copunting the next number in columns RESULT, we ignore the previous values from A, but always use the DISCOUNT from MATURITY=1 forward.
MATURITY
A
R
DISCOUNT
RESULT
1
5
2%
98.0392...%
14,54535...
2
3
3%
97.0874...%
9.737293...
3
7
4%
97.0874...%
6.862745...
Is the any way to do that in Neteza? Without using multiple joins for rates/discounts? Since the dimension of data can vary.

VBA - Validate quantity including the field being edited

Setup: MS Access + SQL Server 2019.
I have Purchase Orders which have to be Delivered. For example:
PurchaseOrderDetailID
QtyOrdered
1
10
DeliveryID
DateShipped
DateReceived
1
1.1.2022
2.1.2022
2
1.2.2022
2.2.2022
DeliveryDetailID
DeliveryID
PurchaseOrderDetailID
QtyDelivered
1
1
1
5
2
2
1
3
This means that there are 10 items ordered, 5 items have been delivered in the first Delivery, 3 items in the second one, therefore 8 delivered in total.
Meaning that this Purchase Order is partially delivered at the moment.
I have a Delivery Data Entry Form in MS Access (back end is SQL Server). I want to validate the quantity so that TotalQtyDelivered cannot be more than TotalQtyOrdered.
Private Sub txtQuantity_BeforeUpdate(Cancel As Integer)
Dim QtyOrdered, QtyDelivered, LeftToDeliver As Double
QtyOrdered = DLookup("QtyOrdered", "dbo_v_PurchaseOrderItemStatus", "PurchaseOrderDetailID=" & Me.PurchaseOrderDetailID)
QtyDelivered = DLookup("QtyDelivered", "dbo_v_PurchaseOrderItemStatus", "PurchaseOrderDetailID=" & Me.PurchaseOrderDetailID)
LeftToDeliver = QtyOrdered - QtyDelivered
If Me.txtQuantity > LeftToDeliver Then
MsgBox "TOO MUCH"
Me.Undo
Cancel = True
End If
End Sub
This works fine if I'm entering a new Delivery. But if I am editing an existing delivery, the algorithm accounts also for the previous value in the Qty field.
With the example above:
QtyOrdered = 10
QtyDelivered = 8
(this is calculated by SQL View)
Let's say that I made a mistake and there were actually 4 items delivered in the second delivery, istead of 3. When I try to change the value, this happens:
Me.txtQuantity = 4
LeftToDeliver = 2
(because it still accounts for the "3" previously inserted in Me.txtQuantity
Result: Operation failed, too many items. However in reality there should only be 9 items.
Can you please advise how I should do this correctly? Thanks.

Counting rows in a table based on multiple array criterias

I am trying to count rows in a table based on multiple criteria in different columns of that table. The criteria are not directly in the formula though; they are arrays which I would like to refer to (and not list them in the formula directly).
Range table example:
Group Status
a 1
b 4
b 6
c 4
a 6
d 5
d 4
a 2
b 2
d 3
b 2
c 1
c 2
c 1
a 4
b 3
Criteria/arrays example:
group
a
b
status
1
2
3
I am able to do this if i only have one array search through a range (1 column) in that table:
{=SUM(COUNTIFS(data[Group],group[group]))}
Returns "9" as expected (=sum of rows in the group column of the data table which match any values in group[group])
But if I add a second different range and a different array I get an incorrect result:
{=SUM(COUNTIFS(data[Group],group[group], data[Status],status[status]))}
Returns "3" but should return "5" (=sum of rows which have 1, 2 or 3 in the status column and a or b in the group column)
I searched and googled for various ideas related to using sumproduct or defining arrays within the formula instead of classifying the whole formula as an array but I was not able to get expected results via those means.
Thank you for your help.
Because your group and status criteria are a different number of values (2 values for group, but 3 values for status), I'm not sure you can do this in a single formula. Best way I know of to do this would be to use a helper column (which can be hidden if preferred).
Put this array formula in a helper column and copy down the length of your data (array formulas must be confirmed with Ctrl+Shift+Enter):
=AND(OR(data[#Group]=group[group]),OR(data[#Status]=status[status]))
And then get the count with: =COUNTIF(helpercolumn,TRUE)
You could use a slightly different approach, using Power Query / Power Pivot.
Name your tables Data, Group and Status, then create the following query, named Filtered Data:
let
tbData = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
tbGroup = Excel.CurrentWorkbook(){[Name="Group"]}[Content],
tbStatus = Excel.CurrentWorkbook(){[Name="Status"]}[Content],
#"Merged Group" = Table.NestedJoin(tbData,{"Group"},tbGroup,{"Group"},"tbGroup",JoinKind.Inner),
#"Merged Status" = Table.NestedJoin(#"Merged Group",{"Status"},tbStatus,{"Status"},"Merged Status",JoinKind.Inner),
#"Removed Columns" = Table.RemoveColumns(#"Merged Status",{"tbGroup", "Merged Status"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Status", type number}})
in
#"Changed Type"
Load To as connection only, and tick Load to Data Model
Now create a DAX measure:
Status Sum:=SUM ( 'Filtered Data'[Status] )
You can then use the following formula on your worksheet, to get the Sum of Status values, for rows matching the criteria specified in the Group and Status tables:
=CUBEVALUE("ThisWorkbookDataModel","[Measures].[Status Sum]")
Simply refresh the data connection to update the value.

Array formula not working in Excel

I have the following table in Excel (blank spaces are empty):
A B C D
1 1
2 3
3 4
4 -2
5 4
6 9
7 8
8
9
10
I would like to return the minimum of column A from A1 to A1000000, using the QUARTILE function, while excluding all negative values. The reason I want it from A1 to A1000000 and not A1 to A7 is because I want to update the table (adding new rows starting from A8) and have the formula also automatically update. The reason I want the QUARTILE and not MIN function is because I will be extending it to calculate other statistics like 1st and 3rd quartile.
This function works correctly and returns 1 (pressing ctrl+shift+enter):
QUARTILE(IF(A1:A7 > -1, A1:A7), 0)
However, when I tried the following, it returned 0 when it should still return 1 (pressing ctrl+shift+enter):
QUARTILE(IF(A1:A1000000 > -1, A1:A1000000), 0)
I also tried the following and it returned 0 (pressing ctrl+shift+enter):
QUARTILE(IF(AND(NOT(ISBLANK(A1:A1000000)), A1:A1000000 > -1), A1:A1000000), 0)
Anybody have a solution to my problem?
Create a dynamic named range, called for example, rng, defined by =OFFSET($A$1,0,0,COUNT($A1:$A10000),1)
Then modify your array formula to refer to rng, via =QUARTILE(IF(rng >-1,rng), 0)
Actually what you have works. Try doing:
=QUARTILE(IF(A:A > 0,A:A ),0)
The reason you are returning 0 is that a blank cell is considered to be of the value 0 when this formula is ran. For example, erase one of the values in the A1:A7 range and your original formula will return 0. Also, I would run the formula on the entire A column if possible (for readability, etc.)
Or do you need to return a "0" if that number is in the list?

VBA two dimensional arrays connecting to a database

I am working with vba in excel and a database in access. The access database is a table that contains 3 columns; OrderIDs which is a column of numbers saying what order the particular item was in, OrderDescription which is a column that contains the description of the item, and Item # which is a column that gives a number to each particular item (if the item is the same as another, they both are the same item).
I need to build a 2-dimensional array in excel using VBA holding which items were purchased in which orders. The rows will be the Order ID and the columns will be the Item ID. The elements of this array will contain an indicator (like True or a “1”) that indicates that this order contains certain items. For example, row 6 (representing order ID 6) will have “True” in columns 1, 5, and 26 if that order purchased item IDs 1, 5, and 26. All other columns for that order will be blank.
In order to do this, i think I will have to determine the max order number (39) and the max item number(33). This information is available in the database which I can connect to using a .connection and .recordset. Some order numbers and some item numbers may not appear.
Note also that this will likely be a sparse array (not many entries) as most orders contain only a few items. We do not care how many of an item a customer purchased, only that the item was purchased on this order.
MY QUESTION is how can I set up this array? I tried a loop that would assign the values of the order numbers to an array and the items numbers to an array and then dimensioning the array to those sizes, but it wont work.
is there a way to make an element of an array return a value of True if it exists?
Thanks for your help
It seems to me that the best bet may be a cross tab query run on an access connection. You can create your array with the ADO method GetRows : http://www.w3schools.com/ado/met_rs_getrows.asp.
TRANSFORM Nz([Item #],0)>0 AS Val
SELECT OrderNo
FROM Table
GROUP BY OrderNo
PIVOT [Item #]
With a Counter table containing integers from 1 to maximum number of items in a column (field) Num.
TRANSFORM First(q.Val) AS FirstOfVal
SELECT q.OrderNo
FROM (SELECT t.OrderNo, c.Num, Nz([Item #],0)>0 AS Val
FROM TableX t RIGHT JOIN [Counter] c ON t.[Item #] = c.Num
WHERE c.Num<12) q
GROUP BY q.OrderNo
PIVOT q.Num
Output:
OrderNo 1 2 3 4 5 6 7 8 9 10 11
0 0 0 0 0 0
1 -1 -1 -1 -1
2 -1 -1 -1 -1

Resources