Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ElPantera
Contributor II
Contributor II

Break-even point from loss of transaction on re-occurring income

Good Day, All!

I hope someone can be of assistance, on my challenge at hand!

I have data from two different sources, the Serial field is the linking field here.

1 = ERP:

This is the actual sale of the product on the ERP system under the invoice in which a loss is made here in the example below;

ERP:

Invoice NumberTransaction DateSerialRevenueCostProfit
IN-0000053011/2/2018 12:00:00 AM14288661748200268-68

 

2 = Re-Occurring Income:

The Product creates a revenue source every month it is used thereafter.

DateSerialMonthly Revenue
07/02/20181428866174891
08/01/20181428866174827

 

So what I have been trying to accomplish is join the re-occurring income onto the ERP system so I will be able to see how long it has taken to recover the loss on the sale from the monthly income. 

So if we do a join we get the below result, there are two lines where the Revenue, Cost, and Profit are being created against both the date field values where it should ideally have a single value for the fields Revenue, Cost, and Profit on the initial transaction date.

SerialRevenueCostProfitMonthly RevenueActual ProfitTransaction DateDateDays to Break Even
14288661748200268-6891231/2/2018 12:00:00 AM07/02/2018181
14288661748200268-6827-421/2/2018 12:00:00 AM08/01/2018211

 

Maybe there is a way to do this in the front end while keeping these tables separate? 

 

I look forward to your input!

Regards

1 Solution

Accepted Solutions
Nicole-Smith

Try running the following (I think I have it doing what you want it to do):

SET DateFormat='M/D/YYYY';
SET TimestampFormat='M/D/YYYY hh:mm:ss[.fff]';

ERP:
LOAD *, [Transaction Date] AS Date, Profit AS [Monthly Revenue] INLINE [
Invoice Number,Transaction Date,Serial,Revenue,Cost,Profit
IN-000005301,1/2/2018,14288661748,200,268,-68
IN-000005302,2/5/2018,04263552905,300,600,-300
];

CONCATENATE (ERP)
LOAD * INLINE [
Date,Serial,Monthly Revenue
7/2/2018,14288661748,91
8/1/2018,14288661748,27
4/19/2018,04263552905,400
6/22/2018,04263552905,400
];

Final:
LOAD Date, Serial, [Monthly Revenue],
	If(Serial = Previous(Serial), Peek([Cumulative Sum]), 0) + [Monthly Revenue] AS [Cumulative Sum],
    If(Peek([Cumulative Sum]) < 0 AND If(Serial = Previous(Serial), Peek([Cumulative Sum]), 0) + [Monthly Revenue] > 0, 1, 0) AS [Break Even Flag]
RESIDENT ERP
ORDER BY Serial, Date;

DROP TABLE ERP;

LEFT JOIN (Final)
LOAD Serial,
	[Break Even Date] - [First Date] AS [Break Even Days],
    1 AS [Break Even Flag];
LOAD Serial,
	Min(Date) AS [First Date],
    Max(If([Break Even Flag] = 1, [Date], 0)) AS [Break Even Date]
RESIDENT Final
GROUP BY Serial;

View solution in original post

6 Replies
Nicole-Smith

I would keep the tables separate on the back-end and join them using a concatenated key that only looks at month and year because your date fields in each table do not align.

ERP:
AutoNumber(Serial & '|' & Month([Transaction Date]) & '|' & Year([Transaction Date]), 'Serial Month Year') AS Key

Re-Occurring Income:
AutoNumber(Serial & '|' & Month(Date) & '|' & Year(Date), 'Serial Month Year') AS Key

After you create the key, you will need to drop the Serial field from one of the two tables (I think you would want to drop it from the Income table).  Then both tables should link only on the Key field.

ElPantera
Contributor II
Contributor II
Author

Hi @Nicole-Smith 

Thank you for your reply. The Key works perfectly in translating the Actual Profit, for say the month. The problem here is if a single serial is selected we wouldn't see the transactional information and rather just the information from the sale.

I need to be able to solve the time it has taken/number of days for it to reach the break-even point i.e Transaction Date - Date which in Qlik would be,

fabs(Date(Transaction Date,'MM/DD/YYYY')) - fabs(Date([Date],'MM/DD/YYYY'))

Based on the below would be 07/02/2018 less 1/2/2018.

SerialRevenueCostProfitMonthly RevenueActual ProfitTransaction DateDateDays to Break Even
Totals200.00268.21-68.21117.8849.67   
14288661748200.00268.21-68.21.00-68.21-1/2/2018 12:00:00 AM-
-.00.00.0091.2891.2807/02/2018--
-.00.00.0026.5926.5908/01/2018--
ElPantera
Contributor II
Contributor II
Author

Hi All,

So I am thinking of working towards a concatenate where my ERP System profit/loss value is the initial point at the date and then the re-occurring income concatenates to give the progress of the "recovery" so looks something like this.

SerialTransaction DateRevenueSource
1428866174801/02/2018-68.21ERP
1428866174807/02/201891.28re-occurring
1428866174808/01/201826.59re-occurring

 

I am going to try something along the lines of a peek and accumulation to see give the date point in which it moves over the zero break-even mark.

Let me know if anyone has ideas on this side!

ElPantera
Contributor II
Contributor II
Author

With Concatenate I have done the following,

SerialTransaction DateRevenueProfit TrendPrevious Date
1428866174801/02/2018-68.21-68.21-
1428866174807/02/201891.2823.0707/02/2018
1428866174808/01/201826.5949.6708/01/2018

 

Here we can see the product breaks-even in 07/02/2018 so we want to go and pull the difference between 07/02/2018 and 01/02/2018 which is 181 days. 

So I created a temp table from the fact table as below to calculate the difference as below,

TMP:
Load *,
if([Serial]=Previous([Serial]),
fabs(Date([Transaction Date],'MM/DD/YYYY')) - fabs(Date(Previous([Transaction Date]),'MM/DD/YYYY'))) as DiffDate
Resident Fact;

BreakEven:
Load
RowNo(),
[Meter Number],
DiffDate,
if([Serial]=Previous([Serial]),
if(sum([Revenue])>0,Peek('DiffDate',-1))) as DateTest
Resident TMP
Group By [Serial],DiffDate;
Drop Table TMP;

 

This gives us a table with the results below which links to the main table through the Serial field.

Meter NumberDateTest
14288661748181

 

Awesome times! So I deiced to throw another Product in there with its unique Serial code to track it as well and this was the result,

SerialTransaction DateRevenueProfit TrendPrevious Date
1428866174801/02/2018-68.21-68.21-
0426355290504/19/2018-394.38-462.59-
1428866174807/02/201891.28-371.31-
1428866174808/01/201826.59-344.72-

 

So the result is obviously not grouping/looking at the specific Serial and now looking at the Revenue field as the as combined across both of them. I was hoping the "if([Serial]=Previous([Serial])" used before the peek would  keep it looking at just the specific Serials. 

 

Any ideas clever people?

Nicole-Smith

Try running the following (I think I have it doing what you want it to do):

SET DateFormat='M/D/YYYY';
SET TimestampFormat='M/D/YYYY hh:mm:ss[.fff]';

ERP:
LOAD *, [Transaction Date] AS Date, Profit AS [Monthly Revenue] INLINE [
Invoice Number,Transaction Date,Serial,Revenue,Cost,Profit
IN-000005301,1/2/2018,14288661748,200,268,-68
IN-000005302,2/5/2018,04263552905,300,600,-300
];

CONCATENATE (ERP)
LOAD * INLINE [
Date,Serial,Monthly Revenue
7/2/2018,14288661748,91
8/1/2018,14288661748,27
4/19/2018,04263552905,400
6/22/2018,04263552905,400
];

Final:
LOAD Date, Serial, [Monthly Revenue],
	If(Serial = Previous(Serial), Peek([Cumulative Sum]), 0) + [Monthly Revenue] AS [Cumulative Sum],
    If(Peek([Cumulative Sum]) < 0 AND If(Serial = Previous(Serial), Peek([Cumulative Sum]), 0) + [Monthly Revenue] > 0, 1, 0) AS [Break Even Flag]
RESIDENT ERP
ORDER BY Serial, Date;

DROP TABLE ERP;

LEFT JOIN (Final)
LOAD Serial,
	[Break Even Date] - [First Date] AS [Break Even Days],
    1 AS [Break Even Flag];
LOAD Serial,
	Min(Date) AS [First Date],
    Max(If([Break Even Flag] = 1, [Date], 0)) AS [Break Even Date]
RESIDENT Final
GROUP BY Serial;
ElPantera
Contributor II
Contributor II
Author

Thank you so much! Working perfectly and as the desired outcome. I am able to see each serial(product) time interval to break-even based on the monthly re-occurring income from the initial sale. 

You the best @Nicole-Smith