Get top(N) or single value using Bql - acumatica

How is it possible to use a PXSelect statement so that it retrieves the Top(N) or the first value for a particular DAC.
Let's say that I have a table with a sequence number and I want to obtain the record with the largest sequence number. How can I do that?
Of course, I would like that for performance reasons, SQL just sends 1 record.

You can use SelectWindowed in place of Select on your PXSelect to get the top N records. In the example below it will get the Top 1. If you change the totalRows value of 1 to 5 it would get the top 5 (except you would have to loop or get the PXResultSet to use all 5 records retrieved.)
Top 1 Example:
DiscountSequence firstRow = PXSelect<DiscountSequence,
Where<DiscountSequence.discountID, Equal<Required<DiscountSequence.discountID>>>
>.SelectWindowed(this, 0, 1, someDiscountID);
Top 5 Example:
foreach (DiscountSequence row in PXSelect<DiscountSequence,
Where<DiscountSequence.discountID, Equal<Required<DiscountSequence.discountID>>>
>.SelectWindowed(this, 0, 5, someDiscountID))
{
//5 rows returned
}

Related

Excel: Match 2 Items, Including if Date is Between a Date Span on Multiple Worksheets

I have 2 worksheets:
Worksheet 1: Member ID, Engagement Date and other data.
Worksheet 2: Member ID, Policy Begin Date, Policy End Date and other data.
On Worksheet 1, I want to return a policy type name (from Worksheet 2), if Worksheet 1's Member ID matches Worksheet 2's Member ID AND if Worksheet 1 Engagement Date falls between Worksheet 2's Policy Begin and End Date...
The following is the formula I tried and also have attempted extensive research, to no avail:
=INDEX('Program Data'!M2:M25671,MATCH(A2:A489&F2>='Program Data'K2&F2<='Program Data'L2,'Program Data'!E2:E25671,0))
Replace your MATCH with an AGGREGATE that Calculates the SMALLest row where the Policy ID and Dates all match up.
So, we want AGGREGATE(15, 6, <SOME CODE>, 1) to get the Smallest non-error value in a list created by <SOME CODE>
The first thing that <SOME CODE> will want is the ROW we are looking at (minus one, because I see that you are skipping the header row...) which is ROW(Sheet2!$A$2:$A$25671)-1
If the Row does not match, we want to either make it massive or make it error (even better, because then it gets completely skipped). How to do this? Well, I have the POWER function for that. If you try POWER(10,999) you get a #NUM! error, because 10^999 is too large a number for Excel. If you try POWER(0,999) you get 0, because 0^anything is 0. So, we'll just add some POWER to our ROWs to make it error-out when we don't want them.
But, now we need to decide between 10 and 0. Fortunately, Logical statements can be treated as Bitwise Multiplication (True = 1 and False = 0`)
So, --(Sheet2!$A$2:$A$25671=$A2) will give us 1 when the First Columns (Member ID) match, --(Sheet2!$B$2:$B$25671<=$B2) will make sure that the Policy Start Date is before-or-on the record date, and --(Sheet2!$C$2:$C$25671>=$B2) will check the End Date. Multiply it all together, and we get 1 when the row matches, and 0 when it doesn't.
Now, if we take that away from 1, we get the opposite: 0 when we want 0, and 1 when we want 10. So multiply that by 10, and shove it in the POWER function, and add that to the ROW to get <SOME CODE>. Dump it all in the AGGREGATE from the start, and voila
=AGGREGATE(15,6,ROW(Sheet2!$A$2:$A$25671)-1+(POWER(10*(1-(Sheet2!$A$2:$A$25671=$A2)*--(Sheet2!$B$2:$B$25671<=$B2)*--(Sheet2!$C$2:$C$25671>=$B2)),999)),1)
Then, just use that in place of your MATCH (it will generate a #NUM! error when no policy is found)
=INDEX(Sheet2!M2:M25671,AGGREGATE(15,6,ROW(Sheet2!$A$2:$A$25671)-1+(POWER(10*(1-(Sheet2!$A$2:$A$25671=$A2)*--(Sheet2!$B$2:$B$25671<=$B2)*--(Sheet2!$C$2:$C$25671>=$B2)),999)),1),1)

Excel, i have a big list (44000 records), i would like to sepperate them into 2 lists, 1 with unique values and 1 with duplicate value's

My list looks somewhat like this:
1. Unique1
2. double1
3. double2
4. unique2
5. double1
6. unique3
7. double2
8. unique4
9. double3
10. double4
and so on..
My wanted output:
list 1
1.unique1
2.unique2
3.unique3
4.unique4
list 2
1.double1
2.double2
3.double3
4.double4
I've only found things like remove/hilight duplicates or count/hilight unique values. But I need to display the values in another list.
Make a PivotTable out of the data. Put the field of interest in it as both a Row Field and as a Values field, and make sure that the aggregation being applied is a Count. (It will be by default if your things are text).
Anything with a Count of 1 is unique. Anything with a count > 1 is not.
You can then optionally copy the PivotTable, and set a Values filter to show where the count = 1 in one, and count > 1 in the other, like so:

How to set values for all rows from group for certain criteria in Tableau

I need to create one Calculated Field "IsProductPresent" (see last column). I have shown here as part of data so that we can compare if our results are right or wrong.
This is basically retail store data - Group of transactions is called Basket (Represented by BasketId) and each item in the basket is one row here (BasketItemNbr). Goal is to find if certain product is present in the basket. If it is present then we should mark "IsProductPresent" to 1 else 0.
What is the criteria for deciding the product?
Criteria is BSKReqID = 308 & ProductBarocde = '0049000000443' , '0049000000450'.
So if there is even one transaction in Basket which satisfies above criteria then IsProductPresent should give me 1 for all the transactions of that basket else 0.
please share emailid so that I can share Sample Data.
You can use LOD calculations for this. One example:
{ FIXED [BasketId] : MAX(IIF([BSKReqID] = 308 AND ([ProductBarcode] = '0049000000443' OR [ProductBarcode] = '0049000000450'), 1, 0)) }
I'll break that down.
IIF([BSKReqID] = 308 AND ([ProductBarcode] = '0049000000443' OR [ProductBarcode] = '0049000000450'), 1, 0)
That's an inline if statement. It says "If the BSKReqID is 308 and the barcode is one of these barcodes, then return 1. Otherwise, return 0."
Then we aggregate that with MAX(). Since the inline if statement can only return a 1 or a 0, MAX() will necessarily return one of those values - 1 if the item is present, 0 if it's not.
{ FIXED [BasketId] : ... }
That says that we're only going to use BasketId in our aggregation. That way, BasketItemNumber will not be included in the MAX() aggregation, and we will calculate that 0 or 1 for the entire Basket rather than for the BasketLineNumber.

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.

Summing the max values when grouping other then exact

I will explain step by step. I'm trying to get one single integer value for a certain key set.
So let's say that i have the following map function
function(doc) {
emit([doc.key1, doc.key2, doc.key3], doc.integerValue);
}
the doc.IntegerValue in this case is a sequence. So let's say that someone makes 0,10,20,30 progress and after that he starts on a new sessionId with once again 0,10,20,30,40.
Now i was trying to reach the following.
1) When doing a group exact it should ouptut the max integerValue found.(first 30, second 40)
2) When doing a group on level 2 it should output the sum according to the max values on scenario 1. So that i can count the total value. So let's assume that key2 and key1 where the same in both examples, it would give me 70.
3) when doing a group on level 1 it should also give 70. as it are the same 2 rows as in the last scenario.
The _stats reduce function does not do the job as it only gives the max of the whole group or the sum of the whole group and my request is a combination of both.
besides that i know, i have the option to leaf the grouping thing out, and then select with startKey and endKey, but i want to check if it is possible with the grouping option.
Thanks in advance for any ideas.!
If you are not interested in stats, why don't you just output the single highest value of integerValue* in your view and use _sum as the reduce function?
// map function
function(doc) {
if(!doc.integerValue || !(doc.integerValue instanceof Array)) return
return ([doc.key1, doc.key2, doc.key3], doc.integerValue.sort().reverse()[0])
}
// reduce function
_sum
This will mean
group_level=exact will output the highest value of the sequence
group_level=2 will output the sum of those single highest values of each sequence
group_level=1 will do the same.
*Assuming integerValue is an array -- I wasn't 100% sure from your question.

Resources