Selective Results

Hi,
I have been working on a report to display a specific set of data, but not sure how to implement the query.

ID . FlagCheck . user
2342 . 0 . userA
4324 . 0 . userA
4323 . 1 . userA
9878 . 0 . userB
7868 . 1 . userB
4534 . 0 . userC

From the above input table, i need to display the below rows only.

ID . FlagCheck . user
9878 . 0 . userB
4534 . 0 . userC

The logic that needs to be implemented is to check when the flag is clear(value=0) but the flag HAS to be uncleared in its previous level. Thats the reason UserA should not show up in this report.

Please advice on how to address this query.


BOB_US (BOB member since 2006-03-16)

IF(flag = '0 and Previous(flag=‘1’)) then ID


Rakesh_K :india: (BOB member since 2007-12-11)

Thanks Rakesh. that syntax did help. However, I cannot created that syntax as a dimension as it would give me a “multivalue error”. The sane way would be to created the formula as a measure.

Since it being a measure, I cannot apply any global filters, and not able to disregard the NULL records.

P.S : please would you be able to provide me this implementation in SQL format.


BOB_US (BOB member since 2006-03-16)

The advise from Rakesh did help, but i am stuck at displaying just those records. Attached is the report and after using the logic, i am able to show just the 30283 and 22156 records.

My main goal is to either display just these two records without the first two columns or a count of 2 without any other columns.

Please advise…
document1.rep (55.0 KB)


BOB_US (BOB member since 2006-03-16)

Can you please once again provide what is your input data and what output you are looking for. please provide in excel sheet or as a screenshot, as I am not able to open your report here.


Rakesh_K :india: (BOB member since 2007-12-11)

The input is from two tables, joining by the ID and HISTID. The Orderid is of importance here as the changes of MIV from 1 to 0 are to be recorded for each Orderid.

Attached is the excel file with the input data and the preferred output.
File1.xls (40.0 KB)


BOB_US (BOB member since 2006-03-16)

Bob, couldn’t you use a correlated subquery for this?

Something like:-

TableName.ID in Select (a.ID from TableName a Where a.MIV = 0 and a.TableName.OrderID = a.OrderID and TableName.MIV = 1)

Mak 1 :uk: (BOB member since 2005-01-06)

Mak,
That code cannot be used for this issue…

Table 1:

ID ::::: HistID ::::: MI ::::: MIV
20824 ::::: 95251 ::::: 0 ::::: 1
22156 ::::: 96983 ::::: 0 ::::: 0
23994 ::::: 99194 ::::: 0 ::::: 0
30016 ::::: 107136 ::::: 0 ::::: 1
30283 ::::: 107481 ::::: 0 ::::: 0

Table 2:
STATUS_ID ::::: OrderID ::::: Personid
95251 ::::: 64814 ::::: 7ying
96983 ::::: 64814 ::::: 7ying
99194 ::::: 64814 ::::: 5hosf
107136 ::::: 64814 ::::: 4yate
107481 ::::: 64814 ::::: 8herm

Table1.HISTID = STATUS_ID
and now for OrderID 64814, there has been two instances where the MIV = 0 (flag cleared) and that is what I need to capture.

So my output should be
count = 2
or
ID = 22156
ID = 30283

Hope I am able to explain the issue clearly…


BOB_US (BOB member since 2006-03-16)

Yes, its clearer now.

What database are you using, if its Oracle you could have a look at the lag function?


Mak 1 :uk: (BOB member since 2005-01-06)

Unfortunately mak… its SQL server that I am using… if only microsoft would have allowed the lag and lead oracle functions to be accepted in sql server…


BOB_US (BOB member since 2006-03-16)

you want output like this.

well first create a variable v_flag = IF(flag = '0 and Previous(flag=‘1’)) then ID

Then drag ID into the report.
and insert a blank column before the ID column. and write ID in that. so your output will be like this.

ID 23332
ID 24354
ID 45666
ID 56678

now apply ranking on ID column for top 1.

You will get only required result.

ID 24354
ID 45666

Give it a try and let us know if it works for you.


Rakesh_K :india: (BOB member since 2007-12-11)

Rakesh,
That logic would/did not work as once the variable is created, it needs the presence of the used columns else it throws up a “computational error”.

An update… i was able to make some progress on the query part though… not entirely …

select distinct min(b.id) , b.orderid from (select d.id, e.orderid from table 1d, table2 e
where d.miv = 0
and d.histid = e.status_id
and d.id in (select id from table1
where histid in (select id from table2
where orderid in (‘64802’,‘64814’))
)
) b,
(select d.id, e.orderid from table 1d, table2 e
where d.miv = 1
and d.histid = e.status_id
and d.id in (select id from table1
where histid in (select id from table2
where orderid in (‘64802’,‘64814’))
)
) c
where b.orderid = c.orderid
and c.id < b.id
group by b.orderid

By using the above Freehand sql, i was able to restrict the data but only 22156 from Table1 shows up and now 30283 from Table1.

I guess… so close yet so far…


BOB_US (BOB member since 2006-03-16)

I tried on my system and the way I suggested working fine. Try again.


Rakesh_K :india: (BOB member since 2007-12-11)

Rakesh,
Please could you post the report. I dont understand what am I doing wrong. I follow your solution step by step, but it doesn’t work. I get a computational error if I were to remove the “MIV” column, and I am not able to apply the ranking as, the variable created which is a measure does not show up in the “based on” drop down during ranking.

Thanks for your much appreciated help…


BOB_US (BOB member since 2006-03-16)

Did you follow these steps?

Don’t add any other column in the report.


Rakesh_K :india: (BOB member since 2007-12-11)

That exactly what i did. Step-by-step… nothing more…

i just could not figure out what the problem is/was…

however, i did find a solution but i had to develop it using a SQL… i had to use the rownum functionality to capture the previous row value, which worked and solved the problem.

but i’d definitely appreciate your help Rakesh…

Thanks.


BOB_US (BOB member since 2006-03-16)