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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
BungleBrain
Frequent Visitor

Count strings in two columns and calculate ratio

I'm trying to get from:

 

Ticket Raised ByTicket Assigned To
BobJohn
JaneEmma
BobJane
JohnBob
JohnNancy
JohnEmma
JaneEmma
EdwardJane
EmmaJane
EmmaBob
BobEmma
BobJane
Bob

Nancy

 

To mentally something like:

 

PersonCount RaisedCount AssignedAssigned/Raised Ratio
Bob520.4
Edward100.0
Emma242.0
Jane242.0
John310.3
Nancy02Error (Infinite)

 

Note that a person can have a count of 0 in either column.

 

Is there a DAX way to get this measure so I can plot it? I've tried a few things but not getting anywhere (DAX novice). Thanks!

1 ACCEPTED SOLUTION
MartynRamsden
Solution Sage
Solution Sage

Hi @BungleBrain 

 

You'll first need to create a table of distinct names. I used the following DAX but there's likely to be a better way:

Names =
DISTINCT (
    UNION (
        ALL ( Table1[Ticket Raised By] ),
        ALL ( Table1[Ticket Assigned To] )
    )
)

 

Once your new table has been created, you may want to rename the column (I called it 'Name').

 

Then create the following measures:

Count Raised = 
VAR SelName = SELECTEDVALUE ( Names[Name] )
VAR Result = 
CALCULATE ( 
    COUNTROWS ( Table1 ),
    Table1[Ticket Raised By] = SelName
)
RETURN Result
Count Assigned = 
VAR SelName = SELECTEDVALUE ( Names[Name] )
VAR Result = 
CALCULATE ( 
    COUNTROWS ( Table1 ),
    Table1[Ticket Assigned To] = SelName
)
RETURN Result
Ratio = DIVIDE ( [Count Assigned], [Count Raised] )

 

When creating your table visualization in Power BI, select the column from the new table and then add your measures.

You should end up with this:

Capture.jpgBest regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Created a common dimension for resources and created the following formulas with One active and one inactive join

 

Assign Count = CALCULATE(COUNT(Ticket[Ticket Assigned To]),USERELATIONSHIP(Assign[Ticket Assigned To],Ticket[Ticket Assigned To]))
Raised Count = CALCULATE(COUNT(Ticket[Ticket Raised By]),USERELATIONSHIP(Assign[Ticket Assigned To],Ticket[Ticket Raised By]))
Assign/Raised Ratio = DIVIDE([Assign Count],[Raised Count])

 

 

Url : https://www.dropbox.com/s/ogir49ju9w8u734/TicketAssignedResolved.pbix?dl=0

 

Screenshot 2020-01-12 15.30.01.pngScreenshot 2020-01-12 15.30.07.png

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
az38
Community Champion
Community Champion

Hi @BungleBrain 

first, create a new table

 

Table Person = 
ADDCOLUMNS(
DISTINCT(UNION(SELECTCOLUMNS(Query;"Person";Query[Ticket Assigned To]);SELECTCOLUMNS(Query;"Person";Query[Ticket Raised By])));
"Count Raised";if(isblank(calculate(countrows(Query);Query[Ticket Raised By]=EARLIER([Person])));0;calculate(countrows(Query);Query[Ticket Raised By]=EARLIER([Person])));
"Count Assigned";if(isblank(calculate(countrows(Query);Query[Ticket Assigned To]=EARLIER([Person])));0;calculate(countrows(Query);Query[Ticket Assigned To]=EARLIER([Person])));

)

 

then add a measure

Assigned/Raised Ratio = DIVIDE([Count Assigned];[Count Raised])

but if you want to get Infinity error you can create a measure

Assigned/Raised Ratio = [Count Assigned]/[Count Raised]

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
MartynRamsden
Solution Sage
Solution Sage

Hi @BungleBrain 

 

You'll first need to create a table of distinct names. I used the following DAX but there's likely to be a better way:

Names =
DISTINCT (
    UNION (
        ALL ( Table1[Ticket Raised By] ),
        ALL ( Table1[Ticket Assigned To] )
    )
)

 

Once your new table has been created, you may want to rename the column (I called it 'Name').

 

Then create the following measures:

Count Raised = 
VAR SelName = SELECTEDVALUE ( Names[Name] )
VAR Result = 
CALCULATE ( 
    COUNTROWS ( Table1 ),
    Table1[Ticket Raised By] = SelName
)
RETURN Result
Count Assigned = 
VAR SelName = SELECTEDVALUE ( Names[Name] )
VAR Result = 
CALCULATE ( 
    COUNTROWS ( Table1 ),
    Table1[Ticket Assigned To] = SelName
)
RETURN Result
Ratio = DIVIDE ( [Count Assigned], [Count Raised] )

 

When creating your table visualization in Power BI, select the column from the new table and then add your measures.

You should end up with this:

Capture.jpgBest regards,

Martyn

 

If I answered your question, please help others by accepting it as a solution. 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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