Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
andymanu
Creator II
Creator II

Retrieve unique number of values to a variable

Hi,

I am running a script to calculate the annualized cost based on the given months of data.

I want to calculate the unique number of months of cost data I got. For example, assume my financial year is from April 2018 to March 2018 and I got the data for April, May and June. Thus, the number of unique months should be"3".

To get this value in to a variable, I used the below code in my data load editor in a temporary table,

('$(Count(DISTINCT Month))') as NoOfMonths

As mentioned above, the variable is NoOfMonths and I need to use that value to perform my subsequent calculations.

The Data loading did work fine but the value I am getting for the "NoOfMonths" variable is not correct.

Could someone help me this issue?

Awaiting for a reply.

Thank you in advance.

Kind regards,

Andy

3 Replies
balabhaskarqlik

May be this:

('$(RangeCount(above(Total Count(Distinct Month),0,3)))')

('$(RangeCount(above(Count(Distinct Month),0,3)))')

andymanu
Creator II
Creator II
Author

Hi Bala,

I tried both the codes but unfortunately still it's not giving me the correct answer.

Let me explain what I am doing may be then it might help you to get a proper understanding.

I am calculating an annualised amount based on the given input number of month's data.

Please refer my data set,

     

Project ComponentsDivisionAprilMayJune
AnalysingDiv_A100120110
PlanningDiv_A120140125
DesingingDiv_A506060
ImplementingDiv_A201530
TestingDiv_A806090

The above data set is for a single division and similarly, I got another two divisions with similar data sets.

The calculation of the annualised amount is = Total Cost of each activity(Analysing, designing, etc) / 3 (which is the number of months) * 12 ( to get the annualised value).

Please find my code below,

Div_A_Actuals:

CrossTable (Month,Costs,2)

LOAD

    "Project Components",

    Division,

    April,

    May,

    June

FROM [lib://Actual_Data/Actual Division Costs.xlsx]

(ooxml, embedded labels, table is [Div-A]);

Temp:

Load "Project Components",

Date(Date#(Month,'MMM'),'MMM') as Month,

Costs

Resident Div_A_Actuals;

Drop Table Div_A_Actuals;

Final:

Load *,

//Count(DISTINCT Month) as NoOfMonths

('$(RangeCount(above(Count(Distinct Month),0,3)))') as NoOfMonths

From [lib://Actual_Data/Temp.QVD] (qvd);

Note

At the moment since I got only 3 months data, the variable value of the "NoOfMonths" should be "3". However, according to my commented code and using of your provided code, it still shows the variable value as 15 (which is "5 Project Components" multiplied by 3.

Hope now it is much clear and look forward to hearing from you.

Thanks

Andy

andymanu
Creator II
Creator II
Author

Hi,

Just a quick addition,

I am using qvd files to store the data and the FROM statement of the Final temporary table  is correct.

Thanks

Kind regards,

Andy