Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi guys
This is a tough one to explain!
I'm migrating data between two systems and using M query to help me!
The first table is the output from the old system and the second table is the input format for the new system.
I need to turn this
Id | Contact name | Company | Quotes | Order Confirmation | Invoice Email | Order Dispatched | statements | Credit Notes | |
2050 | User1 | ACME | user1@domain.com | True | False | False | True | False | False |
2050 | User2 | ACME | user2@domain.com | True | False | True | True | True | True |
2050 | User3 | ACME | user3@domain.com | False | False | False | True | False | True |
2050 | User4 | ACME | user4@domain.com | True | True | True | True | True | False |
2050 | User5 | ACME | user5@domain.com | False | True | True | True | False | True |
Into this
Id | Quotes Email 1 | Quotes Email 2 | Quotes Email 3 | Quotes Email 4 | Quotes Email 5 | Order Conf Email 1 | Order Conf Email 2 | Order Conf Email 3 | Order Conf Email 4 | Order Conf Email 5 | Invoice Email 1 | Invoice Email 2 | Invoice Email 3 | Invoice Email 4 | Invoice Email 5 | Order Disp Email 1 | Order Disp Email 2 | Order Disp Email 3 | Order Disp Email 4 | Order Disp Email 5 | Statements Email 1 | Statements Email 2 | Statements Email 3 | Statements Email 4 | Statements Email 5 | Credit Note Email 1 | Credit Note Email 2 | Credit Note Email 3 | Credit Note Email 4 | Credit Note Email 5 |
2050 | user1@domain.com | user2@domain.com | user4@domain.com | user4@domain.com | user5@domain.com | user2@domain.com | user4@domain.com | user5@domain.com | user1@domain.com | user2@domain.com | user3@domain.com | user4@domain.com | user5@domain.com | user2@domain.com | user4@domain.com | user2@domain.com | user3@domain.com | user5@domain.com |
I've tried using conditional columns but can't get it to work out where to put the email addresses when there's more than one true in the column and keep it to one row.
Then repeat this for around 20,000 customers!
Anyone got any ideas?
Many thanks in advance!
Solved! Go to Solution.
Hi @DaGemsta ,
Here are the steps you can follow:
1. Go to Power Query – Check the yellow label – Unpivot Columns.
Result:
2. Transform – Group -- [id]– Operation:All Rows.
3. Add Column – Custom Column – Enter the following code.
Table.AddIndexColumn([Count],"Rank",1,1)
4. Selected [Count] – Remove.
5. Expand [Custom] - Do not select column [id] - OK.
6. Select the four columns -- right mouse button – in the Merge Column interface – to set the information at the yellow label.
7. Select [Merged] and [Custom.Value] -- Transform – Pivot Column.
Value Column -- [Custom.Email].
Advanced options – Don’t Aggregate.
Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Thank you SO much @Anonymous
Your solution got me most of the way there so I could tweak it and get the result I wanted with the following M query
let
Source = Excel.Workbook(File.Contents("D:\Documents\Go green customers (2).xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"Go green", "Column12"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Delivery notes", "Order Dispatched"}, {"Orders", "Order Confirmation"}, {"Invoices", "Invoice Email"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Quotes", type logical}, {"Order Confirmation", type logical}, {"Invoice Email", type logical}, {"Order Dispatched", type logical}, {"statements", type logical}, {"Credit Notes", type logical}, {"Email", type text}, {"Contact name", type text}, {"Company", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Id", "Contact name", "Company", "Email"}, "Attribute", "Value"),
#"Grouped Rows" = Table.Group(#"Unpivoted Columns", {"Id"}, {{"Count", each _, type table [Id=text, Contact name=text, Company=text, Email=text, Attribute=text, Value=logical]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Rank",1,1)),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Count"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns1", "Custom", {"Contact name", "Company", "Email", "Attribute", "Value", "Rank"}, {"Custom.Contact name", "Custom.Company", "Custom.Email", "Custom.Attribute", "Custom.Value", "Custom.Rank"}),
#"Removed Columns2" = Table.RemoveColumns(#"Expanded Custom",{"Custom.Contact name", "Custom.Company"}),
#"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Removed Columns2", {{"Custom.Rank", type text}}, "en-GB"),{"Custom.Attribute", "Custom.Rank"},Combiner.CombineTextByDelimiter("-", QuoteStyle.None),"Merged"),
#"Filtered Rows" = Table.SelectRows(#"Merged Columns", each ([Custom.Value] = true)),
#"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Merged]), "Merged", "Custom.Email"),
#"Removed Columns3" = Table.RemoveColumns(#"Pivoted Column",{"Custom.Value"}),
#"Renamed Columns1" = Table.RenameColumns(#"Removed Columns3",{{"Invoice Email-3", "Invoice Email 1"}, {"Invoice Email-9", "Invoice Email 2"}, {"Invoice Email-15", "Invoice Email 3"}, {"Invoice Email-21", "Invoice Email 4"}, {"Invoice Email-27", "Invoice Email 5"}, {"Invoice Email-39", "Invoice Email 6"}, {"Invoice Email-33", "Invoice Email 7"}, {"Invoice Email-45", "Invoice Email 8"}, {"Invoice Email-51", "Invoice Email 9"}, {"statements-5", "Statements Email 1"}, {"statements-11", "Statements Email 2"}, {"statements-17", "Statements Email 3"}, {"statements-23", "Statements Email 4"}, {"statements-29", "Statements Email 5"}, {"statements-41", "Statements Email 6"}, {"statements-35", "Statements Email 7"}, {"statements-53", "Statements Email 8"}, {"Credit Notes-6", "Credit Notes Email 1"}, {"Credit Notes-12", "Credit Notes Email 2"}, {"Credit Notes-18", "Credit Notes Email 3"}, {"Credit Notes-24", "Credit Notes Email 4"}, {"Credit Notes-30", "Credit Notes Email 5"}, {"Credit Notes-42", "Credit Notes Email 6"}, {"Credit Notes-48", "Credit Notes Email 7"}, {"Credit Notes-54", "Credit Notes Email 8"}, {"Credit Notes-36", "Credit Notes Email 9"}, {"Quotes-1", "Quotes Emails 1"}, {"Quotes-7", "Quotes Emails 2"}, {"Quotes-19", "Quotes Emails 3"}, {"Quotes-13", "Quotes Emails 4"}, {"Quotes-25", "Quotes Emails 5"}, {"Quotes-37", "Quotes Emails 6"}, {"Quotes-55", "Quotes Emails 7"}, {"Quotes-31", "Quotes Emails 8"}, {"Quotes-43", "Quotes Emails 9"}, {"Order Confirmation-2", "Order Confirmation Email 1"}, {"Order Confirmation-8", "Order Confirmation Email 2"}, {"Order Confirmation-20", "Order Confirmation Email 3"}, {"Order Confirmation-14", "Order Confirmation Email 4"}, {"Order Confirmation-26", "Order Confirmation Email 5"}, {"Order Confirmation-32", "Order Confirmation Email 6"}, {"Order Confirmation-38", "Order Confirmation Email 7"}, {"Order Confirmation-56", "Order Confirmation Email 8"}, {"Order Confirmation-44", "Order Confirmation Email 9"}, {"Order Dispatched-4", "Order Dispatched Email 1"}, {"Order Dispatched-10", "Order Dispatched Email 2"}, {"Order Dispatched-28", "Order Dispatched Email 3"}, {"Order Dispatched-16", "Order Dispatched Email 4"}, {"Order Dispatched-22", "Order Dispatched Email 5"}, {"Order Dispatched-40", "Order Dispatched Email 6"}, {"Order Dispatched-34", "Order Dispatched Email 7"}})
in
#"Renamed Columns1"
LEGEND!!! 😁
Hi @DaGemsta ,
Here are the steps you can follow:
1. Go to Power Query – Check the yellow label – Unpivot Columns.
Result:
2. Transform – Group -- [id]– Operation:All Rows.
3. Add Column – Custom Column – Enter the following code.
Table.AddIndexColumn([Count],"Rank",1,1)
4. Selected [Count] – Remove.
5. Expand [Custom] - Do not select column [id] - OK.
6. Select the four columns -- right mouse button – in the Merge Column interface – to set the information at the yellow label.
7. Select [Merged] and [Custom.Value] -- Transform – Pivot Column.
Value Column -- [Custom.Email].
Advanced options – Don’t Aggregate.
Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
72 | |
70 | |
37 | |
29 | |
27 |
User | Count |
---|---|
91 | |
49 | |
45 | |
38 | |
36 |