Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hey, i have the following problem:
My data is like
Customer, Date, Earnings
A, 01/2022, 10
B, 01/2022, 10
B, 02/2022, 10
C, 01/2022, 10
C, 02/2022, 10
C, 03/2022, 10
and i want to calculate a ytd dimension like
Customer, Date, Earnings, Earnings_YTD
A, 01/2022, 10, 10
B, 01/2022, 10, 10
B, 02/2022, 10, 20
C, 01/2022, 10, 10
C, 02/2022, 10, 20
C, 03/2022, 10, 30
Important: I want to do this in the script.
Any ideas?
As below
DataTable:
LOAD *,
RowNo() as RN;
LOAD * Inline[
Customer,Date,Earnings
A,01/2022,10
B,01/2022,10
B,02/2022,10
C,01/2022,10
C,02/2022,10
C,03/2022,10];
FinalTable:
LOAD *,
IF(RN = 1, Earnings,
IF(Peek('Customer') <> Customer, Earnings, Earnings + Peek('Earnings_YTD'))) as Earnings_YTD
Resident DataTable
Order By Customer,RN;
Drop Table DataTable;
DROP Field RN From FinalTable;
EXIT SCRIPT;
As below
DataTable:
LOAD *,
RowNo() as RN;
LOAD * Inline[
Customer,Date,Earnings
A,01/2022,10
B,01/2022,10
B,02/2022,10
C,01/2022,10
C,02/2022,10
C,03/2022,10];
FinalTable:
LOAD *,
IF(RN = 1, Earnings,
IF(Peek('Customer') <> Customer, Earnings, Earnings + Peek('Earnings_YTD'))) as Earnings_YTD
Resident DataTable
Order By Customer,RN;
Drop Table DataTable;
DROP Field RN From FinalTable;
EXIT SCRIPT;
Works! Thanks a lot.