Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi All,
i have data like the following:
ID | Category | Start Date | End Date | Amount |
A | 1 | 7-May-2007 | 31-May-2007 | $100 |
A | 1 | 1-Jun-2007 | 6-Jun-2007 | $85 |
A | 1 | 7-Jun-2007 | 6-May-2008 | $50 |
A | 1 | 7-May-2008 | 6-May-2009 | $70 |
A | 3 | 7-May-2007 | 31-May-2007 | $20 |
A | 3 | 1-Jun-2007 | 6-Jun-2007 | $12 |
A | 3 | 7-Jun-2007 | 6-May-2009 | $15 |
A | 4 | 1-Jun-2007 | 6-Jun-2007 | $5 |
A | 4 | 7-Jun-2007 | 6-May-2009 | $5 |
i need to achieve the following result:
ID | Start Date | End Date | Amount |
A | 7-May-2007 | 31-May-2007 | $100 + $20= $120 |
A | 1-Jun-2007 | 6-Jun-2007 | $85 + $12 + $5= $102 |
A | 7-Jun-2007 | 6-May-2008 | $50 + $15 + $5 = $70 |
A | 7-May-2008 | 6-May-2009 | $70 + $15 + $5 = $90 |
As the start and end date are not entirely similar among the category, i can't directly do a group by.
The way i thought of is by looping it by day but it'll be slow.
Any idea is highly appreciated. Thanks a lot!
load id , start Date , min ( End date ) , sum ( Amount )
from table
Ivanildo Buarque wrote:load id , start Date , min ( End date ) , sum ( Amount )
from table
You mean this?
[Charges]:
LOAD
"Tenant"
,"Start Date"
,min("End Date") as "End Date"
,sum("Amount") as "Amount"
RESIDENT [Raw Data]
GROUP BY
"Tenant"
,"Start Date"
;
That doesn't work because some of the service and miscellaneous charges are supposed to apply to more than one base rental period. This approach only applies them to the first base rental period.
Thanks a lot, John!
i was creating a table for each category and join them together but was having issue with null.
Thanks again!
hey John,
i just read your explanation on the rounding function. what would you expect to get after rounding 12345.555 to 2 decimals point in QV?
if my script is :
load round(12345.555, 0.01) as rd autogenerate 1;
i'll get 12345.55
if my script is:
Z:
LOAD * INLINE
[A,B
12345.555,211.3213123];
LOAD
round(A,0.01) as A,
num(B, '#,##0.00') as B,
A as OriA,
B as OriB
Resident Z;
drop table Z;
i'll get 12345.56.
putting =round(12345.555, 0.01) on text object will return me 12345.55 as well.
According to QlikView's documentation, you should get 12345.56, but the documentation doesn't always match reality due to the limitations of binary floating point for representing decimal numbers.
One possible explanation (for which I have almost no evidence) would be if QlikView uses more than one numeric format internally. My understanding was that it was using IEEE double precision binary floating point for all numbers, but Rob Wunderlich's memory usage analysis indicated that shorter numbers took less memory, perhaps indicating a second numeric format. Perhaps the second format is IEEE single precision binary floating point. That allows for 24 binary digits, which in general can only store seven decimal digits, but your eight-digit number can technically squeeze in since it is small. So my theory is that when you use 12345.555 individually in a table or text box, it gets represented with single-precision, but when you combine it in a table with 211.3213123, that has enough digits to require double-precision for the column, resulting internally in a slightly-different approximation, one which rounds up instead of down.
It should be easy to gather some evidence for or against this theory. I need to leave this open in a tab and do that later today.
Edit: Well, that theory's already out the window. I see that you put them in separate columns instead of rows, which should give QlikView the ability to use different formats for each number. I'll need to think of another theory.