Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
mahendragaur
Creator
Creator

Compare Previous Values

Hello,

Below is my requirement Name, Group, Date. I sorted the data based on Name (Asc) and Date (Dsc). Yellow highlighted is my latest group and I want to check the number of occurrence of the latest group for the same user and if it finds then in next column (Next Step), it should update the previous value of Group else 0.

Please let me know which function I can use to compare the previous value in whole column based on same name.

   

NameGroupDateNext Step
Mahendra1111/25/20160
Mahendra111/24/20160
Mahendra121/23/20160
Mahendra111/22/20160
Mahendra1111/21/201611
Mahendra111/20/20160
Mahendra1111/15/201611
Mahendra1111/12/2016111
Nishant113/20/20160
Nishant111/19/201611
Nishant1111/18/20160
Nishant110/15/20120
1 Solution

Accepted Solutions
Kushal_Chawda

Data:

LOAD Name,

    Group,

    Date

FROM

[Book1.xlsx]

(ooxml, embedded labels, table is Sheet1);

Left Join(Data)

LOAD Name,

    max(Date) as Date,

    1 as Flag

Resident Data

Group by Name;

Left Join(Data)

LOAD

    Name,

    Group as NewGroup

Resident Data

where Flag=1;

    

Group:

LOAD *,

    if(RowNo()=1 or Name<>Previous(Name),0,if(Group=NewGroup,Peek(Group),0)) as Output

Resident Data

order by Name,Date desc;

DROP Table Data;

Capture.JPG

Update: Script and application updated

View solution in original post

8 Replies
Anil_Babu_Samineni

We have functions Aggr() and Above() combination here

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
mahendragaur
Creator
Creator
Author

I want to compare the current value of Group with the whole column if it matches then it should return the previous value in the next step

Anil_Babu_Samineni

Yes, We can use like below

If(Aggr(Value = CurreneValue,Group), Before(Value)','NA')

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
sunny_talwar

Not sure I understand what you are looking to do... Would you be able to expand and elaborate with an example?

mahendragaur
Creator
Creator
Author

Yellow highlighted is the latest value of group i.e. 111 and if the same value is present in the same column(Group) and for the same name (Mahendra) then it should update the previous value in the column (Next Step). like it is doing 11 and 111 when it found match else 0.

Kushal_Chawda

Data:

LOAD Name,

    Group,

    Date

FROM

[Book1.xlsx]

(ooxml, embedded labels, table is Sheet1);

Left Join(Data)

LOAD Name,

    max(Date) as Date,

    1 as Flag

Resident Data

Group by Name;

Left Join(Data)

LOAD

    Name,

    Group as NewGroup

Resident Data

where Flag=1;

    

Group:

LOAD *,

    if(RowNo()=1 or Name<>Previous(Name),0,if(Group=NewGroup,Peek(Group),0)) as Output

Resident Data

order by Name,Date desc;

DROP Table Data;

Capture.JPG

Update: Script and application updated

mahendragaur
Creator
Creator
Author

Thanks Buddy. This is what I was expecting

Kushal_Chawda

Glad that it was helpful