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

Expression to count the union of two columns

Dear Community,

this is a problem I'm trying to solve in the presentation layer without resorting to script changes. In short, I have two columns of names in my data, and I want to count the number of distinct names in the union of the two columns, per dimension value.

My data describes the relationships between marketing relationship managers globally - who is passing leads & deals to whom transnationally. Its columns include

  • DealId (PK)
  • CustomerIndustrySegment (Utilities, Resources, etc.)
  • FromRelationshipManager
  • ToRelationshipManager
  • PotentialDealSize

I am needing to count all the distinct Relationships Managers (RM) for each Industry Segment, irrespective of whether the RM is a FromRelationshipManager or a ToRelationshipManager. Note that (a) RMs are frequently in both columns(b) An RM can be in both columns for the same deal, if the deal is both discovered and handled within the one country.

Example:

DealIdCustomerIndustrySegmentFromRelationshipManagerToRelationshipManager
1UtilitiesAnneAnne
2UtilitiesBobCharlie
3UtilitiesDorothyDorothy
4UtilitiesDorothyEgbert
5UtilitiesFelicityEgbert
6UtilitiesFelicityGeorge
7UtilitiesGeorgeGeorge
8ResourcesHelenGeorge

Given the above, I'm wanting to generate

  • Utilities - 7 (being all RMs from A to G)
  • Resources - 2 (being George & Helen)

So, in pseudocode, for each CustomerIndustrySegment, I am wanting count(union of (distinct FromRelationshipManagers and distinct ToRelationshipsManagers for the given CustomerIndustrySegment)).

I've considered expressions that attempt to mix'n'match various counts, like (in pseudocode):

  • count(distinct FromRelationshipsManager) + count(distinct ToRelationshipsManager) - count(distinct FromRelationshipsManager in records for which FromRelationshipsManager<>ToRelationshipsManager)

(this gives 8 and 1 for Utilities and Resources respectively)

but cannot find anything that gives the right result.

The only solution I've been able to come-up with is to change my data, unpivoting the Relationship Manager columns in the script so that we have

DealIdCustomerIndustrySegmentDirectionRelationshipManager
1UtilitiesFromAnne
1UtilitiesToAnne
2UtilitiesFromBob
2UtilitiesToCharlie
3UtilitiesFromDorothy
4UtilitiesToDorothy
::::


and then we could use count(distinct RelationshipManager). But I'd rather not change the underlying data, if I can help it.

Does anyone know how to achieve what I'm trying to do?

1 Reply
gussfish
Creator II
Creator II
Author

Hmm, I'm inferring from the lack of response to my question that it can't be done - or at least, no-one knows how to do it. Am I right?