Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
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: 
Not applicable

Calculate value based on no data

Hello. I hope somebody could tell me how to do the following (and if it's possible using QlikView 11)

I need to create report for stock analysis and one of the calculated properties burns my mind.

There are entities named Portfolio. These portfolios contain a sets of positions (wich are stocks).

Each position starts some day from 1000$ and ends in another day with some value

For example:

Bob's portfolio

DateMSAPPL
1
21000
3800
410001500
513001400
61400
71200
8
9
10

Now I need to calculate a specific value for this whole portfolio for days 3-9. and here is how It should be calculated

(SUM(ALL_POSITIONS_END_DATE) / SUM(ALL_POSITIONS_START_DATE))

And here is the trick. My start date is 3 so MS should be 1000 and APPL 800 => SUM() = 1800

My end date is 9 so MS should be 1200 and APPL 1400 => SUM() = 2600

2600 / 1800 =  1,4444

But there are no data for MS days 3, 8, 9 and APPL days 6-9. I need to emulate it as I have the following dataset

Bob's portfolio

DateMSAPPL
1
2
31000800
410001500
513001400
614001400
712001400
812001400
912001400
10
6 Replies
maxgro
MVP
MVP

If you can populate the fields in the load script you can follow this

http://community.qlik.com/blogs/qlikviewdesignblog/2013/02/05/populating-a-sparsely-populated-field

Anonymous
Not applicable
Author

lAnubisl


You could try creating a Master Calendar containing all dates from a suitable Start Date to a suitable End Date, and join that to your Fact table.


Then you'll have all the dates you require to report on, albeit some dates will have no rows in the Fact table but that can be accommodated.



Best Regards,     Bill

greg-anderson
Luminary Alumni
Luminary Alumni

Have you tried the FIRST() and LAST() functions on each column?  They should pull the first and last value, respectively, for each field/column, within the selected date range.

Not applicable
Author

Hello Greg

First() and Last() cannot be used inside aggregation functions such as Sum()

Not applicable
Author

Hello Massimo.

That is a fantastic blog post but I'm afraid it will not solve my problem.

Here is a link to example QW file.

And here is a screenshot from it.

qw.PNG.png

I need to make it work for each PortfolioId, Stock records separately.

2 1 MS 5

2 1 APPL 8

3 1 MS 4

3 1 APPL 8

4 1 MS 7

4 1 APPL 8

5 1 MS 6

5 1 APPL 6

......

maxgro
MVP
MVP

Aleksander, check the image (I added some stocks and portfolios) and if answers to your question see the attachments .qvw

435894.jpg