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
Anonymous
Not applicable

Using values in table as main column for new table

Hello Community,

 

I have a table that looks like this:

 

Workflow #RequesterApprover1Approver2Processor1Processor2Processor3
12345BobJimNULLMaryNULLNULL
12346BobFrankSarahJanetMaryNULL
12347BillMaryJimNancyJakeBob

 

What I want is to know how many times someone's "touched" something, basically if a name shows up in ANY field (Requester, Approver1, Approver2, Processor1, Processor2, Processor3), to count that Workflow Number towards their total. So the result (ideally) would look like this:

 

NameWorkflow Count
Bob3
Jim2
Mary3
Frank1
Janet1
Bill1
Nancy1
Jake1

 

Since Bob's name showed up on each line item (doesn't matter which column), he gets a count of 3 workflows, Jim 2 etc. Each line item is based on Workflow Number (it's my primary key, so all unique values). How do I populate those names spread out across multiple fields, condense it into a singular column, and then show how many times their names were associated with a workflow (e.g. Jim is approver1 for workflow #12345 and approver for workflow #12347, so his count is 2). If it helps, if a name is in one of the fields it'll unlikely be repeated. Please help, thanks! 

 

 

 

2 ACCEPTED SOLUTIONS
parry2k
Super User
Super User

@Anonymous best way to achieve this would be to unpivot your table.

 

in query editor, click workflow #, right click and select "unpivot other columns"

 

you will get two column "attribute" and "value", rename value to "name", apply the changes.

 

in table visual, drop name and workflow # and change the aggregation to workflow # to count, and you will get the result.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

Anonymous
Not applicable

Hi there, OP here: Turns out the "Unpivot Other Columns" Power Query M solution, while valid, only works on import tables and not DirectQuery. However I could use UNPIVOT() on the SQL side to get the results how I wanted and just import the results table. This is my query  

 

select B.Name,count(workflow_number) as Workflow_Count
     from (
                 select Workflow_Number, Position, Name
                      from Workflow_Table
                           UNPIVOT(
                                             Name
                                             FOR Position in (Requester, Approver1, Approver2, Processor1, Processor2, Processor3)
                                           ) AS A
                ) as B
Group by Name
order by name asc

 

 

which give me output like this (Which is what I wanted):

 

Name                       WF_Count
Aaron Carter             5704
Aaron D. Price          4880
Aaron Random         92
Abby Dates               24
Abby Kamehameha  92

 

Hopefully that helps y'all as well

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi there, OP here: Turns out the "Unpivot Other Columns" Power Query M solution, while valid, only works on import tables and not DirectQuery. However I could use UNPIVOT() on the SQL side to get the results how I wanted and just import the results table. This is my query  

 

select B.Name,count(workflow_number) as Workflow_Count
     from (
                 select Workflow_Number, Position, Name
                      from Workflow_Table
                           UNPIVOT(
                                             Name
                                             FOR Position in (Requester, Approver1, Approver2, Processor1, Processor2, Processor3)
                                           ) AS A
                ) as B
Group by Name
order by name asc

 

 

which give me output like this (Which is what I wanted):

 

Name                       WF_Count
Aaron Carter             5704
Aaron D. Price          4880
Aaron Random         92
Abby Dates               24
Abby Kamehameha  92

 

Hopefully that helps y'all as well

parry2k
Super User
Super User

@Anonymous best way to achieve this would be to unpivot your table.

 

in query editor, click workflow #, right click and select "unpivot other columns"

 

you will get two column "attribute" and "value", rename value to "name", apply the changes.

 

in table visual, drop name and workflow # and change the aggregation to workflow # to count, and you will get the result.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

@parry2k it worked! Idk how to mark it as solved or anything, but it got me what I wanted, thank you!

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.