Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Ther_Rider
Contributor II
Contributor II

How to calculate the month wise count and percentage

Table

Sr_number Month_Closure Category
1 Oct-2022 A
2 Oct-2022 A
3 Oct-2022 B
4 Oct-2022 B
5 Oct-2022 A
6 Oct-2022 B
7 Oct-2022 B
8 Oct-2022 C
9 Oct-2022 A
10 Oct-2022 C
11 Oct-2022 C
12 Nov-2022 A
13 Nov-2022 C
14 Nov-2022 C
15 Nov-2022 B
16 Nov-2022 A
17 Nov-2022 B
18 Dec-2022 C
19 Jan-2023 C
20 Jan-2023 A
21 Jan-2023 A
22 Jan-2023 B
23 Jan-2023 A
24 Jan-2023 A
25 Feb-2023 B
26 Feb-2023 B
27 Feb-2023 A
28 Feb-2023 A
29 Feb-2023 C
30 Feb-2023 A

 

How to calculate the month wise count and percentage  in pivot as below

Category Oct-2022 Nov-2022 Dec-2022 Jan-2023 Feb-2023 Grand Total
A 36.36% 33.33% 0.00% 66.67% 50.00% 43.33%
B 36.36% 33.33% 0.00% 16.67% 33.33% 30.00%
C 27.27% 33.33% 100.00% 16.67% 16.67% 26.67%
Grand Total 100.00% 100.00% 100.00% 100.00% 100.00% 100.00%

 

 

 

Labels (1)
1 Reply
Aasir
Creator III
Creator III

First customize your load script

// Load your data
Table:
LOAD
Sr_number,
Month_Closure,
Category
FROM [your_data_source.csv]
(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

// Create a mapping table for month order
MappingTable:
Mapping LOAD
Month_Closure,
MonthOrder
Inline [
Month_Closure, MonthOrder
Oct-2022, 1
Nov-2022, 2
Dec-2022, 3
Jan-2023, 4
Feb-2023, 5
];

// Join the mapping table to the main data
Table:
LOAD
Sr_number,
Month_Closure,
Category,
MonthOrder
RESIDENT Table;

DROP TABLE MappingTable;

// Create a pivot table
PivotTable:
PivotTable
LOAD
Category,
'Oct-2022',
'Nov-2022',
'Dec-2022',
'Jan-2023',
'Feb-2023'
RESIDENT Table;

DROP TABLE Table;

// Calculate the count for each combination of Category and Month
CountTable:
LOAD
Category,
'Oct-2022',
'Nov-2022',
'Dec-2022',
'Jan-2023',
'Feb-2023',
Count(Sr_number) as Count
RESIDENT PivotTable
GROUP BY Category, Month_Closure;

DROP TABLE PivotTable;

// Calculate the percentage
PercentageTable:
LOAD
Category,
'Oct-2022',
'Nov-2022',
'Dec-2022',
'Jan-2023',
'Feb-2023',
Count / Sum(Total Count) as Percentage
RESIDENT CountTable
GROUP BY Category;

DROP TABLE CountTable;

 

Now count is 
=Sum(Count)
& Percentage is
=Num(Sum(Percentage), '0.00%')

Will get auto-customized based on the placed you use. Try in your tables.