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: 
psk180590
Creator III
Creator III

Count and generate new Columns

Hello All,

I have my sample data and expected result in two different tabs of the attached excel sheet. Please, have a look at the data to understand my problem better.

An basic overview: I have few IDs generated randomly and i'm looking to generate the Count of IDs per Region, State and Country.

Please Note: I need the Count not Sum.

The method i tried is:

1. Read all the Sample data, generate Count(IDs) as IDBasis and store in Basis.qvd.

2. Read from Basis.qvd. Without the Region, do a Sum(IDBasis) as IDState and store as Region.qvd

3. Read from Region.qvd. Wothout the State, do a Sum(IDState) as IDCountry and store as State.qvd

4. Do a left Join and read all the three qvd files into a Datamodell

But, i always end up getting the same count for each type.

No selection all the three Values are same. If state selected all the three values change where as IDCountry shouldn't samething when a region is selected both the IDState and IDCountry change.

Thanks in Advance.

Wishing you all a Happy and Safe Diwali 

1 Solution

Accepted Solutions
florentina_doga
Partner - Creator III
Partner - Creator III

3 Replies
florentina_doga
Partner - Creator III
Partner - Creator III

pls see attach

felipedl
Partner - Specialist III
Partner - Specialist III

Hi Pakalapati,

The following script should give you the result:

Data:

LOAD Country,

     State,

     Region,

     ID

FROM

(ooxml, embedded labels, table is Data);

RegionCount:

Load

Region,

Country,

    State,

Count(Region) as RegionCount

Resident Data

Group by Country,

     State,

     Region;

StateCount:

Load

Country,

    State,

Count(State) as [State Count]

Resident Data

Group  by Country,

     State;

IDCount:

Load

count(ID) as [Total Count]

Resident Data;

left join(Data)

Load

Region,

Country,

    State,

RegionCount

Resident RegionCount;

left join(Data)

Load

Country,

State,

[State Count]

Resident StateCount;

join (Data)

Load

[Total Count]

Resident IDCount;

drop tables RegionCount,StateCount,IDCount;

Giving the following table:

Sample.png

effinty2112
Master
Master

Hi Pakalapati,

Try:

Data:

LOAD Country,

     State,

     Region,

     ID

FROM

[..\Sample Data.xlsx]

(ooxml, embedded labels, table is Data);

Left Join(Data)

LOAD

Region,

count(ID) as [Region Count]

Resident Data Group by Region;

Left Join(Data)

LOAD

State,

count(ID) as [State Count]

Resident Data Group by State;

Left Join(Data)

LOAD

count(ID) as [Total Count]

Resident Data;

to get:

Country State Region ID Region Count State Count Total Count
INDAPAMDE411025
INDAPANDD511025
INDAPGUHJ811025
INDAPKLIJ811025
INDAPONJH611025
INDAPPOLK811025
INDAPSKGG511025
INDAPTPFR511025
INDAPVJAA211025
INDAPVZJK711025
INDMHAUHZ61725
INDMHMUA342725
INDMHMUGH52725
INDMHNPAD61725
INDMHPUA232725
INDMHPUFG42725
INDMHSHAF41725
INDTGADTH61825
INDTGHYKI81825
INDTGKMZH61825
INDTGMKZT61825
INDTGNZWE61825
INDTGRRRE31825
INDTGSCTZ51825
INDTGWROL91825

Kind regards

Andrew