Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi!
I have a table with Employees, Account , DataAccount,Bench
This is a part of my table:
Employee | Account | Period | DataAccount | Bench |
Mark Spencer | Telecom | Feb-15 | 1.00 | 0 |
Mark Spencer | Telecom | Mar-15 | 1.00 | 0 |
Mark Spencer | Telecom | Apr-15 | 1.00 | 0 |
Mark Spencer | Telecom | May-15 | 1.00 | 0 |
Mark Spencer | Telecom | Jun-15 | 1.00 | 0 |
Mark Spencer | Telecom | Jul-15 | 1.00 | 1 |
Mark Spencer | Telecom | Aug-15 | 1.00 | 1 |
Mark Spencer | Telecom | Sep-15 | 1.00 | 1 |
Mark Spencer | Telecom | Oct-15 | 1.00 | 1 |
Mark Spencer | Telecom | Nov-15 | 1.00 | 1 |
Mark Spencer | Telecom | Dec-15 | 1.00 | 1 |
I need to find the last row before the values in Bench appear like this:
Employee | Account | Period | DataAccount | Bench | Flag |
Mark Spencer | Telecom | Feb-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Mar-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Apr-15 | 1.00 | 0 | |
Mark Spencer | Telecom | May-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Jun-15 | 1.00 | 0 | 1 |
Mark Spencer | Telecom | Jul-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Aug-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Sep-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Oct-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Nov-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Dec-15 | 1.00 | 1 |
This should work:
Data_raw:
LOAD *, DATE(DATE#(Period, 'MMM-YY')) AS Date INLINE [
Employee, Account, Period, DataAccount, Bench
Mark Spencer, Telecom, Feb-15, 1.00, 0
Mark Spencer, Telecom, Mar-15, 1.00, 0
Mark Spencer, Telecom, Apr-15, 1.00, 0
Mark Spencer, Telecom, May-15, 1.00, 0
Mark Spencer, Telecom, Jun-15, 1.00, 0
Mark Spencer, Telecom, Jul-15, 1.00, 1
Mark Spencer, Telecom, Aug-15, 1.00, 1
Mark Spencer, Telecom, Sep-15, 1.00, 1
Mark Spencer, Telecom, Oct-15, 1.00, 1
Mark Spencer, Telecom, Nov-15, 1.00, 1
Mark Spencer, Telecom, Dec-15, 1.00, 1
];
Data:
LOAD
*,
IF(Employee = PEEK(Employee) AND Bench <> PEEK(Bench), 1) AS Flag
RESIDENT
Data_raw
ORDER BY
Employee ASC,
Date DESC;
DROP TABLE Data_raw;
HTH Peter
this has been working for me
if(Employee = Previous(Employee) and Account = Previous(Account) and DataAccount = Previous(Account),
if( Previous(Bench)= Bench, peek('Flag') 1),0) as Flag
Nope,
it shows me an Error.
peek ('Flag') expression isn't working
In this case you have to explore the next record to see if the bench has change, but this is no possible. In this case i do the following:
T1:
Load.... " your table"
Then...
Join (T1)
Load Employee, Account, Max(Period) as Period, DataAccount, Bench, 1 as Flag
Resident T1
Where Bench = 0
Group By Employee, Account, DataAccount, Bench;
Check it out...
no, it doesnt give me the desired result. I want it to show me exactly like that:
Employee | Account | Period | DataAccount | Bench | Flag |
Mark Spencer | Telecom | Feb-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Mar-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Apr-15 | 1.00 | 0 | |
Mark Spencer | Telecom | May-15 | 1.00 | 0 | |
Mark Spencer | Telecom | Jun-15 | 1.00 | 0 | 1 |
Mark Spencer | Telecom | Jul-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Aug-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Sep-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Oct-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Nov-15 | 1.00 | 1 | |
Mark Spencer | Telecom | Dec-15 | 1.00 | 1 |
was missing a comma
temp:
LOAD Employee,
Account,
Period,
DataAccount,
Bench
FROM
[Test.xlsx]
(ooxml, embedded labels, table is Sheet1);
temp:
load
Employee,
Account,
Period,
DataAccount,
Bench,
if(Employee = Previous(Employee) and Account = Previous(Account) and DataAccount = Previous(DataAccount),
if(Previous(Bench)= Bench, peek('Flag'), 1),0) as Flag
resident temp
order by Employee,Period,Account ;
drop table temp;
if you only want it to show for when the change happen switch it to this
if(Employee = Previous(Employee) and Account = Previous(Account) and DataAccount = Previous(DataAccount),
if(Previous(Bench)= Bench, null(), 1)) as Flag
I want to mark the row just before the change happens
This should work:
Data_raw:
LOAD *, DATE(DATE#(Period, 'MMM-YY')) AS Date INLINE [
Employee, Account, Period, DataAccount, Bench
Mark Spencer, Telecom, Feb-15, 1.00, 0
Mark Spencer, Telecom, Mar-15, 1.00, 0
Mark Spencer, Telecom, Apr-15, 1.00, 0
Mark Spencer, Telecom, May-15, 1.00, 0
Mark Spencer, Telecom, Jun-15, 1.00, 0
Mark Spencer, Telecom, Jul-15, 1.00, 1
Mark Spencer, Telecom, Aug-15, 1.00, 1
Mark Spencer, Telecom, Sep-15, 1.00, 1
Mark Spencer, Telecom, Oct-15, 1.00, 1
Mark Spencer, Telecom, Nov-15, 1.00, 1
Mark Spencer, Telecom, Dec-15, 1.00, 1
];
Data:
LOAD
*,
IF(Employee = PEEK(Employee) AND Bench <> PEEK(Bench), 1) AS Flag
RESIDENT
Data_raw
ORDER BY
Employee ASC,
Date DESC;
DROP TABLE Data_raw;
HTH Peter
I think you can use the last solution if you do this:
...
Order by Employee, Acouunt, Bench desc, Period desc;