Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Eparfitt1002
Regular Visitor

DAX Count Unique Id when another column contains two values in different rows.

Hello ! 

 

I have a dataset with one column that contains a unique ID that indicates a phone call and another calumn that has tags of subjects detected during those calls. If a single call has 4 tags, then that means the same unique I'd would be in all 4 rows and the tags would be in the tags column in different rows.

 

How can I write a DAX metric to count the number of times two tags appear together in the same unique ID? 

 

I want to use that number to include in a percentage calculation. Obviously a calculate / keepfilter option won't work because the "tags" are all in the same column.

 

Any help would be appreciated!

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @Eparfitt1002 
Could you please attach a table with an example of data and the desired results so that we can better understand your request?

View solution in original post

@Eparfitt1002 
In order to achieve the desired outcome.
The first step is to add a calculated column that concatenates the texts by ID to the "height"
Dax Funtion:

Concatenated Text = CONCATENATEX(FILTER('Table', 'Table'[UniqueID] = EARLIER('Table'[UniqueID])), 'Table'[Tags], ", ")
Ritaf1983_1-1683083819847.png

 


 

A second step involves counting based on whether the combination you are seeking is present.
DAX formula for a measure

Counter = CALCULATE(DISTINCTCOUNT('Table'[UniqueID]),CONTAINSSTRING('Table'[Concatenated Text],"Escalated Client, Agent Expressed Empathy"))

 

Ritaf1983_2-1683083972290.png

**If string order can also be reversed, you can add another comparison
with OR condition

Link to sample File 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



View solution in original post

5 REPLIES 5
Ritaf1983
Super User
Super User

Hi @Eparfitt1002 
Could you please attach a table with an example of data and the desired results so that we can better understand your request?

Certainly! 

 

In the below example, I would want this formula to detect when Tags "Agent Expressed Empathy" and "Escalated Client" were both on the same call, and count the number of times that happens. 

 

The below table would be a count of 1 when this happened on Call 4. 

UniqueIDTags
Call 1Store Issue
Call 1Escalated Client
Call 2Billing Issue
Call 3Website Issue
Call 4Escalated Client
Call 4Agent Expressed Empathy
Call 5Billing Issue

Do you only check that combination?

Right. I'm attempting to create a percentage that calculates how often my agents are using empathy during escalated calls. 

 

So if it has the same UniqueID and those two values, it would count that call. Then I'll divide whatever that count is by the count of all the escalation calls to express it as a percentage. 

 

Thanks!

@Eparfitt1002 
In order to achieve the desired outcome.
The first step is to add a calculated column that concatenates the texts by ID to the "height"
Dax Funtion:

Concatenated Text = CONCATENATEX(FILTER('Table', 'Table'[UniqueID] = EARLIER('Table'[UniqueID])), 'Table'[Tags], ", ")
Ritaf1983_1-1683083819847.png

 


 

A second step involves counting based on whether the combination you are seeking is present.
DAX formula for a measure

Counter = CALCULATE(DISTINCTCOUNT('Table'[UniqueID]),CONTAINSSTRING('Table'[Concatenated Text],"Escalated Client, Agent Expressed Empathy"))

 

Ritaf1983_2-1683083972290.png

**If string order can also be reversed, you can add another comparison
with OR condition

Link to sample File 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.