Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
dmohanty
Partner - Specialist
Partner - Specialist

If Else condition

Hi Team,

This could look simpler, but somehow I am stuck to get the logic. Can some one please help here? 

Requirement

If any User has an ID as 'C' - then the Role would be 'Manager'. At same time the all Zones would be falling under Role = 'Manager'.

If the User does not have an ID as 'C' , then the Role would be 'Sales Rep'.

Sample Data-

UserIDZone
JohnANorth
JohnBSouth
JohnCEast
JohnDWest
MaryANorth
MaryBSouth
MaryDWest
BobANorth
BobCEast
RichCEast
LucyANorth
LucyBSouth

 

Expected Output - 

UserIDZoneRole
JohnANorthManager
JohnBSouthManager
JohnCEastManager
JohnDWestManager
MaryANorthSales Rep
MaryBSouthSales Rep
MaryDWestSales Rep
BobANorthManager
BobCEastManager
RichCEastManager
LucyANorthSales Rep
LucyBSouthSales Rep

 

Regards!

Labels (2)
1 Solution

Accepted Solutions
sunny_talwar

May be this

Table:
LOAD * INLINE [
    User, ID, Zone
    John, A, North
    John, B, South
    John, C, East
    John, D, West
    Mary, A, North
    Mary, B, South
    Mary, D, West
    Bob, A, North
    Bob, C, East
    Rich, C, East
    Lucy, A, North
    Lucy, B, South
];

Left Join (Table)
LOAD If(SubStringCount('|' & Concat(DISTINCT ID, '|') & '|', '|C|') = 1, 'Manager', 'Sales Rep') as Role,
	 User
Resident Table
Group By User;

View solution in original post

6 Replies
sunny_talwar

May be this

Table:
LOAD * INLINE [
    User, ID, Zone
    John, A, North
    John, B, South
    John, C, East
    John, D, West
    Mary, A, North
    Mary, B, South
    Mary, D, West
    Bob, A, North
    Bob, C, East
    Rich, C, East
    Lucy, A, North
    Lucy, B, South
];

Left Join (Table)
LOAD If(SubStringCount('|' & Concat(DISTINCT ID, '|') & '|', '|C|') = 1, 'Manager', 'Sales Rep') as Role,
	 User
Resident Table
Group By User;
StarinieriG
Partner - Specialist
Partner - Specialist

Hi,

try with something like this

Left Join
LOAD Distinct
User,
'Manager' as Role
Resident table
Where ID='C'
;

NoConcatenate
output:
LOAD
User,
ID,
Zone,
If(Len(Role)=0,'Sales Rep',Role) as Role
Resident table;

DROP Table table;

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hi @sunny_talwar ,

 

Thank you for the logic. This has helped in getting the desired results. 

Even if I select the Role = 'Manager', that doesnt filter out the Zone as East and shows all Zones.

 

Regards!

 

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hi @StarinieriG ,

 

Thank you for supporting. 

However, this again filters out the Zone values when Role is selected. 

If I select the Role = 'Manager', that filters out the Zone as East and other Zones are greyed out. The desired output has to show all Zones available for that User.

sunny_talwar

Is this a question or a statement?

"Even if I select the Role = 'Manager', that doesnt filter out the Zone as East and shows all Zones."

dmohanty
Partner - Specialist
Partner - Specialist
Author

Hi @sunny_talwar ,

Sorry for the confusion.

That was the statement, and solution working as desired.

The requirement was NOT to filter out the East Zone only, rather show all 4 Zones , when Manageris selected. So its working proper.

Thanks again!