Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
paulinhok14
Creator
Creator

Rolling Last 24 Months Metric - Line Chart

Hello all!

I'm developing an application to compare my real Demands against my Forecast data. 

I have a primary key called "%PairKey" that represents a specific material in a specific region. This material has an Acq Cost, and I have a date column called "Forecast Slice Date", that is a month/year info.

Each Forecast Slice Date, for each PairKey, has a Forecast Value and a real Demanded value. Example below:forecast.png


 

 

 

 

 

 

 

I calculate my financial accuracy in L24M by making it this way:
Total Forecast (L24M) = Acq Cost * Forecast Qty L24M
Total Demand (L24M) = Acq Cost * Demanded Qty L24M

See how I do it (validated) in my text object:

 

 

=

	Num (
	
		// "1 - " because Deviation is what is calculated, so we define Accuracy as the inverse
		Fabs (1 -
	
		// Absolute difference between Demanded and Forecast
	
		Fabs (
		
			Sum (
			
				Aggr (
			
					Sum ( [Forecast Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
			
			-
			
			Sum (
			
				Aggr (
			
					Sum ( [Demanded Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
		)
		
		// Divided by Demand (real value that is intended to predict)
		/
		Sum (
			
				Aggr (
			
					Sum ( [Demanded Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
	
	) * 100
	
	, '#.##0,00')

		& '%'

 

 


When I make L24M selections on Forecast Slice Date, it calculates correctly (around 84%).

But I want a line chart when, for each month in timeline, it calculates the L24M, like this:

paulinhok14_0-1714685293879.png


Is there any easy way to do it without changing script?

I've tried, without success, to build a table chart with "Forecast Slice Date" in Dimension and an Expression like that:

 

 

=

	Num (
	
		// "1 - " because Deviation is what is calculated, so we define Accuracy as the inverse
		Fabs (1 -
	
		// Absolute difference between Demanded and Forecast
	
		Fabs (
		
			Sum (
			
				Aggr (
			
					Sum ( {< [Forecast Slice Date] = {">$(=AddMonths ( Max ( [Forecast Slice Date] ), -24 ) )"} >} [Forecast Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
			
			-
			
			Sum (
			
				Aggr (
			
					Sum ( [Demanded Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
		)
		
		// Divided by Demand (real value that is intended to predict)
		/
		Sum (
			
				Aggr (
			
					Sum ( [Demanded Qty] ) * [Acq Cost]
					
				, [%PairKey] )
			
			)
	
	) * 100
	
	, '#.##0,00')

		& '%'

 

 


Any ideas?

Thank you!

Labels (1)
1 Reply
Lech_Miszkiewicz
Partner Ambassador/MVP
Partner Ambassador/MVP

The easiest one is to build grouping calendar. So you link in the grouping calendar MonthYear with all 24 MonthYears which should belong to rolling 24 periods. When you make a selection on one of those you should have 24 months selected in your calendar. 

Then you use that as your dimension in the chart.

cheers

cheers Lech, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful to the problem.