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

Grouping in a LOAD statement

Hi everyone,

I am stuck with one issue which suppose to be easy to accomplish. I know this can be done with expressions but I must do that in a LOAD script.

I have similar kind of data:

YearPositionEmployee IDGender
2014DeveloperXX1Female
2014AccountantXX2Female
2014DeveloperXX3Male
2014DeveloperXX4Male
2015DeveloperXX5Male
2015AccountantXX6Male
2015DeveloperXX7Male
2015DeveloperXX8Female
2016DeveloperXX9Female
2016AccountantXX10Male
2016AccountantXX11Male
2016DeveloperXX12Female
2017AccountantXX13Male
2017AccountantXX14Female
2017AccountantXX15Female
2017DeveloperXX16Male

I am trying to load from this table (to drop it later) and to achieve a new table in a data model that would have dominated flag column (F- if there are more females in the position that year and M if there are more males in the position that year) . The result table suppose to look like this:

YearPositionFlag
2014DeveloperM
2014AccountantF
2015DeveloperM
2015AccountantM
2016DeveloperF
2016AccountantM
2017DeveloperM
2017AccountantF

How to achieve that? I tried to do grouping by and aggregate but somewhat failed...

Your help will be greatly appreciated!

1 Solution

Accepted Solutions
sunny_talwar

Try this

Table:

LOAD * INLINE [

    Year, Position, Employee ID, Gender

    2014, Developer, XX1, Female

    2014, Accountant, XX2, Female

    2014, Developer, XX3, Male

    2014, Developer, XX4, Male

    2015, Developer, XX5, Male

    2015, Accountant, XX6, Male

    2015, Developer, XX7, Male

    2015, Developer, XX8, Female

    2016, Developer, XX9, Female

    2016, Accountant, XX10, Male

    2016, Accountant, XX11, Male

    2016, Developer, XX12, Female

    2017, Accountant, XX13, Male

    2017, Accountant, XX14, Female

    2017, Accountant, XX15, Female

    2017, Developer, XX16, Male

];


Left Join (Table)

LOAD Year,

Position,

If(Count(If(Gender = 'Female', [Employee ID])) > Count(If(Gender = 'Male', [Employee ID])), 'F', 'M') as Flag

Resident Table

Group By Year, Position;

View solution in original post

4 Replies
sunny_talwar

Try this

Table:

LOAD * INLINE [

    Year, Position, Employee ID, Gender

    2014, Developer, XX1, Female

    2014, Accountant, XX2, Female

    2014, Developer, XX3, Male

    2014, Developer, XX4, Male

    2015, Developer, XX5, Male

    2015, Accountant, XX6, Male

    2015, Developer, XX7, Male

    2015, Developer, XX8, Female

    2016, Developer, XX9, Female

    2016, Accountant, XX10, Male

    2016, Accountant, XX11, Male

    2016, Developer, XX12, Female

    2017, Accountant, XX13, Male

    2017, Accountant, XX14, Female

    2017, Accountant, XX15, Female

    2017, Developer, XX16, Male

];


Left Join (Table)

LOAD Year,

Position,

If(Count(If(Gender = 'Female', [Employee ID])) > Count(If(Gender = 'Male', [Employee ID])), 'F', 'M') as Flag

Resident Table

Group By Year, Position;

PrashantSangle

bro, you are really very quick. Nice solution.

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
sunny_talwar

thank you

summerrain
Contributor III
Contributor III
Author

Thanks for a quick solution Sunny!