Summarize more than one column in Excel COM object - excel

I'm using SubTotal in a Openedge generated Excel book for my first time.
The example of the KB (https://knowledgebase.progress.com/articles/Article/Sample-Code-to-do-Excel-Grouping) is:
chWorksheet:Range("A1"):CurrentRegion:Subtotal(1, -4112, 2, True, False, False).
The parameters for SubTotal are:
GroupBy , Function:, TotalList, Replace:, PageBreaks:, SummaryBelowData:
In "TotalList" the example is 2, which means column 2 is totalized.
In VBA, TotalList can be an array. For example, Array(14, 15) indicates totaling columns 14 and 15.
But I can't make ABL to accept that. It only receives an integer, for one column. Which is sad.
Does anybody if it's possible to totalize more than one column?
Thank you

Instead of an integer, I sent an integer EXTENT variable with the column numbers and it worked perfectly.
Thanks to Tom and Jensd for the help and ideas.

Related

Excel CUBEVALUE & CUBESET count records greater than a number

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!

Excel sum based on matrix condition and multiple criteria

Following from the example here I'm trying to add additional conditions to a sum formula. I've represented an example below:
The output that I'm looking for for example for Jan 2017 is
2017
1
UP A 1
UP B 6
UP C 6
DOWN A 1
DOWN B 8
DOWN C 7
I tried with the following formula:
=MMULT(--($B$17:$C$17="X"),MATCH(1,($A23=$C$2:$C$14)*(C$21=$A$2:$A$14)*(C$22=$B$2:$B$14)*($E$2:$E$14=$D$2:$D$14),0))
but I get a N/A value.
Does anyone know it if is possible to do it?
In your first example the number of rows in array1 and number of columns in array2 were equal, five. Here you have two columns and 13 rows. That they are unequal here is part (all) of the reason why you are having an issue.
Also your match function is returning a Boolean not an array
I have a way to do this using matrix condition and multiple criteria but had to change problem up a bit, see photo for example:
{=MMULT(--(D18:P18="x"),E$2:E$14*(--(A$2:A$14=$C$21)*--(B$2:B$14=$C$22)*--(C$2:C$14=A24)))"
https://i.stack.imgur.com/FEvgR.png
You can create a formula to fill the second matrix with X's see below
=IF(OR(INDIRECT("D"&VALUE(D20))=$A$18,INDIRECT("D"&VALUE(D20))=$B$18),"X","")
https://i.stack.imgur.com/4rS4L.png
That being said I don't think this is particularly efficient as you are treating the one of the matrixes as a all 1's so you basically just adding an extra criteria / Boolean with added complexity....that being said u asked for this specifically and I believe that I have delivered that LOL
Just add two SUMIFS together.
=SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 1)="x", $B$16))+
SUMIFS($E$2:$E$14, $A$2:$A$14, C$21, $B$2:$B$14, C$22, $C$2:$C$14, $A23, $D$2:$D$14, IF(INDEX($B$17:$C$19, MATCH($B23, $A$17:$A$19, 0), 2)="x", $C$16))

EXCEL: Find cells via last number

So I need a way to mark the cells where the sequence ends in 4, 5, or 6.
Data
35632
35215
35115
etc.
I don't have an idea of where to start so any help is much appreciated. I know that I can't use the text filters on numbers even if the cell is formatted as text.
You could use one of the following Excel formulas
=OR(MOD(A1,10)=4,MOD(A1,10)=5,MOD(A1,10)=6)
or
=OR(RIGHT(A1)="4",RIGHT(A1)="5",RIGHT(A1)="6")
or (thanks to Scott Craner)
=ISNUMBER(MATCH(--RIGHT(A1),{4,5,6},0))
or
=ISNUMBER(MATCH(MOD(A1,10),{4,5,6},0))
or
=ISNUMBER(FIND(MOD(A1,10),"456"))
or
=ISNUMBER(FIND(RIGHT(A1),"456"))
or
=SUM(IF(MOD(A1,10)={4,5,6},1)) (returns 1 if true, or 0 if false)
OR
=OR(MOD(A1,10)={4,5,6})
Or
=MOD(MOD(A1,10),7)>3
Or
=ABS(RIGHT(A1)-5)<2

Excel: Countifs on Multiple Columns and Only on Visible Rows (Filtering)

I've seen several forum posts with the answer to this question, but I can't really understand how it's supposed to work, so I figured I'd come here for an explanation.
I have three columns:
CITY........|.Attribute 1.|.Attribute 2.|
Chicago..|........1........|........1........|
Chicago..|........1........|..................|
Boston....|........1........|........1........|
Chicago..|..................|..................|
Boston....|..................|..................|
Boston....|..................|........1........|
Chicago..|........1........|........1........|
Chicago..|........1........|........1........|
I want to get a count of the number of times a city has a "1" in Attribute 1 and Attribute 2. Normally, you would use COUNTIFS (=COUNTIFS(B2:B9,"1",C2:C9,"1"))which would give you the value of 4 - Rows 2, 4, 8, and 9.
But I want to be able to filter this list on the fly, and only be able to see data for Chicago rows, for instance. And thus, want to see the value of 3 - Rows 2, 8, and 9. But when the data is filtered, I still get the value of 4.
What code do I need to insert into my cell to get the value of 3 after filtering my list to only show Chicago, if I want to see when a city has a "1" in both Attribute 1 and Attribute 2?
Thanks!
Would this not work for Chicago?:
=COUNTIFS(A2:A9, "Chicago", B2:B9,"1", C2:C9, "1")
This would not require you to filter the data.
A variant of this could be used:
SUMPRODUCT((Attribute 1.=Satisfactory)*(SUBTOTAL(103,OFFSET(AW3,ROW(tblStudentProgress[D3 Activity])-MIN(ROW(tblStudentProgress[D3 Activity])),0))))
You could also create a helper column and sum attributes 1 and 2. If your helper column row equals 2 then you know both attributes exist. You could take this one step further and use concatenate to combine "Chicago" and your sum. And then filter by Chicago2.

Using a subset of excel entries for calculation

Assume that you have 5 cells with values:
[12, 23, 50, 89, 95]
and you are interested in finding the average of the four largest entries (that is drop 12 because it is the smallest).
I wonder how one can do that in excel?
You can get the average of the largest 4 from 5 with this formula
=AVERAGE(LARGE(A1:E1,{1,2,3,4}))
that will only average 4 values even if there are duplicates
Generically if you might have a variable number of values then to average without the smallest value you can use this version
=(SUM(Range)-MIN(Range))/(COUNT(Range)-1)
again that will work OK with duplicates - of course there must be at least 2 numbers in the range
You can use AVERAGEIF(range,condition)
So in your case, it will be AVERAGEIF(A1:E1,">"&MIN(A1:E1))
Hope this helps..
Use =LARGE to get the วน-th largest value then use =SUMIF to add if the value is larger than the n-th value!
In pseudocode something like this: =SUMIF(data >= LARGE(range, n))/n, sorry it's been a while since I used excel. `

Resources