I have column family with timestamp as row name and I want to fetch first 10 rows, second 10's, etc.
family = { //CF
TimeUUID: value,
...
I know that I can set column-limit for first query and get first n-th rows, but how can I get next n-th rows?
get_range_slices (use the last key from the previous query as the first key in the next query)
Related
I have records with several line items. I need to return the record and the max value of a flag that reviews the line items. A simplified version of the code without getting the max value for the flag is:
Select nvl(order.order_value, order2.order_value) as "order",
case when item.item_no in ('abc','def','ghi') then 'Y' else 'N' end as "Flag",
field 3,
field 4
from order
left join order2 on order.order_value=order2.order_value
left join item on item.order_value=order.order_value
The actual current code does have a lot of other fields selected from other various tables/subqueries.
My issue is that there are multiple items in the item table per order_value, and I only want one line per order. I want the flag to say yes if any item falls in the my 'y' list.
I want to count the number of rows since the last occurrence of a specific value, while excluding rows where the cell is a blank or empty value. I have provided a sample of fake data to try to explain what I'm asking. So, with the sample data, on every occurrence of "Apple", I would like to show the number of valued rows since the last occurrence of "Apple". I currently have a formula like this:
=ROW()-MAX(FILTER(ROW(INDIRECT("B1:B"&ROW()-1)),INDIRECT("B1:B"&ROW()-1)=INDIRECT("B"&ROW())))
The formula gives me the number of rows since the last occurrence, but does not exclude the blank cells, and I'm wanting to figure out a way to get this result without counting the rows with blank cells in the column.
Sample Data
Assuming values are in range A2:A and we want the results in column B, use this formula in cell B2 and then manually extend down:
=IF(A2="Apple",IFERROR(MATCH("Apple",QUERY({A$2:A2,SEQUENCE(ROWS(A$2:A2))},"select Col1 where Col1 is not null order by Col2 desc offset 1"),0),0),)
Explanation
The QUERY retrieves all values above the current one (e.g. for row 7 it will be A2:A6) in reverse order (A6, A5, ..., A2) and excluding blanks.
MATCH returns the position of the first occurrence of the value in interest in the result of the QUERY.
I was not able easily to make this formula auto-extend using ARRAYFORMULA or MAP(LAMBDA), so it has to be manually extended.
I have the following table in PowerPivot. I'd like to create a column ("Show") that will have the name of the quarter corresponding to the highest rank for all rows with the same ID. The table below shows the desired end state where "Show" is the calculated column I'm after:
Assuming your table is called 'DimShow', the following DAX should do the trick:
LOOKUPVALUE(
'DimShow'[Quarter],
'DimShow'[ID], 'DimShow'[ID],
'DimShow'[Rank],
CALCULATE(
MIN('DimShow'[Rank]),
ALLEXCEPT('DimShow', 'DimShow'[ID])
)
)
Explanation:
We want to lookup a value from the [Quarter] column that has the same [ID] as the current row. At the same time, the [Rank] value should be the minimum value for all rows that has the same [ID] as the current row.
Note that this will produce an error, if there are more than one distinct value of [Quarter] for the same (lowest) rank, within a specific [ID].
I usually use a variable to do this:
Show =
VAR TopRank = CALCULATE(MIN(Table1[Rank]), ALLEXCEPT(Table1, Table1[ID]))
RETURN CALCULATE(
MAX(Table1[Quarter]),
ALLEXCEPT(Table1, Table1[ID]),
Table1[Rank] = TopRank)
The TopRank variable calculates what the highest rank is for that ID. The second line essentially looks up what the Quarter value is for that rank and that ID.
In SSAS, I wanted to create a measure that counts the number of rows which the column values contains a specific string.
eg. table
|Id|item
|1|greenapple
|2|blueapple2
|3|yellowapple
|4|purplegrape
search for "apple".
i want the measure return 3.
how should i write the DAX expression?
thanks.
Step 1 first add a column in your table
AppleFlag := if(SEARCH("apple",Table1[Name],1,0)>0,1,0)
Step 2 then create Measure
Apple Count := SUM(Table1[AppleFlag])
I am selecting a table that has multiple of the same records (same REQUEST_ID) with different VERSION_NO. So I want to sort it descending so I can take the highest number (latest record).
This is what I have...
IF it_temp2[] IS NOT INITIAL.
SELECT request_id
version_no
status
item_list_id
mod_timestamp
FROM ptreq_header INTO TABLE it_abs3
FOR ALL ENTRIES IN it_temp2
WHERE item_list_id EQ it_temp2-itemid.
ENDIF.
So version_no is one of the SELECT field but I want to sort that field (descending) and only take the first row.
I was doing some research and read that SORT * BY * won't work with FOR ALL ENTRIES. But that's just my understanding from reading up.
Please let me know how I can make this work. Thanks
You can simply sort the itab after the select and delete all adjecent duplicates afterwards, if wanted:
SORT it_abs3 BY request_id [ASCENDING] version_no DESCENDING.
DELETE ADJACENT DUPLICATES FROM it_abs3 COMPARE request_id.
Depending on the amount of expected garbage (to be deleted lines) in the itab an SQL approach is better. See Used_By_Already's answer.
If you are using the term "latest" to indicate "the most recent entry", then the field mod_timestamp appears to be relevant and you could use it this way to choose only the most recent records for each request_id.
SELECT
request_id
, version_no
, status
, item_list_id
, mod_timestamp
FROM ptreq_header h
INNER JOIN (
SELECT
request_id
, MAX(mod_timestamp) AS latest
FROM ptreq_header
GROUP BY
request_id
) l
ON h.request_id = l.request_id
AND h.mod_timestamp = l.latest
If you want the largest version_no, then instead of MAX(mod_timestamp) use MAX(version_no)
Just declare the it_abs3 as a sorted table with key that would consist of the columns you want to sort by.
You can also sort the table after the query.
SORT it_abs3 BY ...