Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
kunkumnaveen
Specialist
Specialist

How to add a Fiscal Year

Hello All,

Below is the list of the columns in a table ,where valid from and valid to are the calendar date.

Plant              Supplier             Part                 ValidFrom        ValidTo                  Price

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100

I am trying to add a column Fiscal year in above table which has to be derived from valid from and valid to columns ,as shown below

Plant              Supplier             Part                 ValidFrom        ValidTo                  Price     FiscalYear

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100       2018

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100       2019

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100       2020

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100       2021

 HP                    Jolt                     Screw             05-01-2018        25-07-2021          100       2022

as the Valid from of a price for the specified plant,supplier,part is from 05-01-2018   and valid to 25-07-2021 ,which means the price is valid for more than 4 calender Yrs in term of Fiscal year it will be more than 5 yrs.

so i need to derive a column name Fiscal Year from valid from and Valid to for  a plant,supplier,part combination

 

How to achieve this at backend scripting 

 

 

Thanks

Naveen

Labels (1)
3 Replies
rodjager
Partner - Creator
Partner - Creator

Hi Naveen,

The first thought I had was to run some for loops over the data.  

I know there is going to be a better (more efficient) way of doing this, probably using IntervalMatch or something like that, however, I suspect this will do what you want too.

Hope this helps.

Rod 

// Load in the data
[Data]:
Load * Inline[
Plant, Supplier, Part, ValidFrom, ValidTo, Price
HP, Jolt, Screw, 05-01-2018, 25-07-2021, 100
];

// Loop through and add the FiscalYear field to the original data set
Let vParts = FieldValueCount('Part');

For i = 1 to $(vParts)
	vStart = Peek('ValidFrom', $(i)-1, 'Data');
	vEnd = Peek('ValidTo', $(i)-1, 'Data');
	
	Let vYears = Year(Date#(vEnd, 'DD-MM-YYYY')) - Year(Date#(vStart, 'DD-MM-YYYY'));
	
	For j = 0 to $(vYears)
	
	[Final data]:
	Load
		Year(Date#('$(vStart)', 'DD-MM-YYYY')) + $(j)	As FiscalYear,
		*
	Resident Data;
	Next j
Next i
	
// Tidy up by removing definitions table
Drop Table Data;

 

Brett_Bleess
Former Employee
Former Employee

Here is a Design Blog post on Fiscal Year calendar that may be helpful:

https://community.qlik.com/t5/Qlik-Design-Blog/Fiscal-Year/ba-p/1472103

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
Kushal_Chawda

@kunkumnaveen  try below

[Data]:
LOAD *,
     FiscalYearStart+IterNo()-1 as FiscalYear
While FiscalYearStart+IterNo()-1<=FiscalYearEnd;

LOAD *,
     year(YearStart(ValidFrom,0,4))+1 as FiscalYearStart,
     year(YearStart(ValidTo,0,4))+1 as FiscalYearEnd;

Load * Inline[
Plant, Supplier, Part, ValidFrom, ValidTo, Price
HP, Jolt, Screw, 05-01-2018, 25-07-2021, 100
];

DROP Fields FiscalYearStart,FiscalYearEnd;

 

Annotation 2020-09-08 235621.png