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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anon29
Helper II
Helper II

Grouping Problem in Power Query

Hi all, I am struggling to figure how to get this grouping to work in the Power BI desktop Power Query. 

 

My goal is to group the data so that it shows in one row the Date, Agent Talk ID, Talkorder and stat1 and stat2 all in one row. It needs to be done in Power Query.

Here's my rawdata. The full data has many different Talk ID with the similar structure.

DateAgentTalk IDTalkorderStat1Stat2
12/06/2023Bat Womanzqy321411300 
12/06/2023Bat Womanzqy321414 1
12/06/2023Wonder Girlzqy321611500 
12/06/2023Wonder Girlzqy321612  
12/06/2023Wonder Girlzqy321613 1
12/06/2023Bat Womanzqy321416  
12/06/2023Bat Womanzqy321417  
12/06/2023Robinhoodzqy321811  
12/06/2023Robinhoodzqy321812670 
12/06/2023Hookzqy3211111 1
12/06/2023Hookzqy3211112  
12/06/2023Hookzqy3211113360 
12/06/2023Robinhoodzqy321818  
12/06/2023Robinhoodzqy3218110  
12/06/2023Kenzqy3211311480 
12/06/2023Wonder Girlzqy3216113  
12/06/2023Robinhoodzqy3218112 1
12/06/2023Super Manzqy3211611100 
12/06/2023Barbiezqy3211711  
12/06/2023Barbiezqy3211712423 
12/06/2023Barbiezqy3211713 1
12/06/2023Bat Womanzqy32121119011

 

I would like the result to be like this below.  My problem is getting the Talkorder to display like below. If the talkorder for the same agent starts with the same digits, then it can be grouped together, like Wonder Girl having 611 and 6113 can be together since they start with 61. 

Anon29_1-1698295539844.png

Bat Woman has Talkorders that start with 41X and 211X which means she talked to the customer twice on the same call (call transferred back to Bat Woman). 

 

Can someone please help me on this

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Anon29 ,

 

The issue here is that the logic required appears to change between [Talkorder] values.

Per your example, you seem to want to group Bat Woman on a 41X and 211X basis. This would be solved by creating a new [Talkorder] column to group on that just cuts off the last digit, something like this:

Text.Start(Text.From([Talkorder]), Text.Length(Text.From([Talkorder])) - 1)

 

However, applying this logic then fails to group Robin Hood under a single [Talkorder] value of 81, as this would require evaluating [Talkorder] on both a 81X and 81XX basis. Similarly, it appears as though Wonder Girl's calls need to be evaluated on both a 61X and 61XX basis. This is mixed logic. 

 

Can you provide any additional information that would identifiy the type of logic that should be used in each scenario based on the data please?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

4 REPLIES 4
BA_Pete
Super User
Super User

Hi @Anon29 ,

 

The issue here is that the logic required appears to change between [Talkorder] values.

Per your example, you seem to want to group Bat Woman on a 41X and 211X basis. This would be solved by creating a new [Talkorder] column to group on that just cuts off the last digit, something like this:

Text.Start(Text.From([Talkorder]), Text.Length(Text.From([Talkorder])) - 1)

 

However, applying this logic then fails to group Robin Hood under a single [Talkorder] value of 81, as this would require evaluating [Talkorder] on both a 81X and 81XX basis. Similarly, it appears as though Wonder Girl's calls need to be evaluated on both a 61X and 61XX basis. This is mixed logic. 

 

Can you provide any additional information that would identifiy the type of logic that should be used in each scenario based on the data please?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thanks Pete, I think I may have found a working solution, just need to test it on a larger set of data. What I ended up doing was adding an extra column to capture the first two numbers of the Talkorders. Then grouping everything by date, name, talkid, newtalkorder. I then added the Table.Min column record based of the subtable of the grouped data to find the first Talkorder. Not sure if this is the most efficient way though.

 

Ok. This method doesn't sound like it would give you the output you requested intially. Taking the record with the min 2-digit [newtalkorder] would remove [newtalkorder] = 41 for Bat Woman, wouldn't it?

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




No because the 2 digits ended up grouping all the talk orders the way I wanted it to and also seperate Bat Woman's 41x and 211x talkorders. Then by adding in the min column of the rawdata Talkorder into the sub table of the groupping, I was able to get what I wanted. 

 

I also bookmarked your links as well, they are extremely useful and will definetitly be referring back to it when I'm working with sub tables within columns.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors