Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
parpatra
Partner - Contributor III
Partner - Contributor III

Simple YTD

MonthLobAmountYTD
1/1/2010A1010
1/1/2010B1515
1/1/2010C2020
2/1/2010A2535
2/1/2010B3040
2/1/2010C3555
3/1/2010A4075
3/1/2010B4585
3/1/2010C50105


The YTD column is the expected result. Can you please help me with the expression using the sample data.

5 Replies
jonathandienst
Partner - Champion III
Partner - Champion III

Hi

Use this script (modified to fit your data):


LOAD
TranDate,
Product,
Qty,
If (Product = Previous(Product) AND Year(TranDate) = Year(Previous(TranDate)), RangeSum(Peek('YTD'), Qty), Qty) AS YTD,
If (Product = Previous(Product) AND Month(TranDate) = Month(Previous(TranDate)), RangeSum(Peek('YTD'), Qty), Qty) AS MTD
RESIDENT tmpData
ORDER BY Product, TranDate
;


See attached for an example.

Hope that helps

Jonathan

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
parpatra
Partner - Contributor III
Partner - Contributor III
Author

Thanks Jonathan...

But I was trying to handle it in an expression...is that possible?

johnw
Champion III
Champion III

Perhaps this?

rangesum(Amount,if(year(Month)=year(above(Month)),above(YTD)))

I generally try to avoid using above(), though, as it depends on the exact way the chart is displayed and sorted. I prefer a data solution. I'd create an AsOf table. See the below post for a similar question and my suggested solution.

http://community.qlik.com/forums/t/36252.aspx

parpatra
Partner - Contributor III
Partner - Contributor III
Author

Can I use SET analysis to show YTD on Bar chart using the above data set?

I was able to put it in a pivot without any dimension, but it fails when we add a dimension.

=sum({<Month={"<=Month">}>} Amount) (Syntax might be incorrect)

Also I dnot want to have full accumulation option to be selected. Since when I select only 'feb' it should show me just one bar with FEB YTD value, which is not the case in full accumulation.

Thanks!!

johnw
Champion III
Champion III

You can't use set analysis for this because the set is only calculated once, not once for each row (each Month in this case) in your chart.