Excel and Power BI Stacking Grouped Columns Challenge

  Рет қаралды 2,544

Access Analytic

Access Analytic

Күн бұрын

The team and I at Access Analytic develop Power BI and Excel solutions for clients in Australia and deliver training around the World. accessanalytic...
👏🏻 Update - thanks to @ianrhile for suggesting a simpler approach avoiding GroupBy and utilising INTEGER DIVIDE. I've added that method to the demo file below
Demo File
aasolutions.sh...
Submit alternative solutions to info@accessanalytic.com.au
A super simple DYNAMIC ARRAY formula such as
=WRAPROWS(TOCOL(Table1,1),3) could solve this solution if it was a one off Excel only solution
Did you know I've written a book "Power BI for the Excel Analyst"?
pbi.guide/book/
Connect with me
wyn.bio.link/

Пікірлер: 50
@AccessAnalytic
@AccessAnalytic Ай бұрын
Check out the description section if you want to play along. A super simple DYNAMIC ARRAY formula such as =WRAPROWS(TOCOL(Table1,1),3) could solve this solution if it was a one off Excel only solution
@ianrhile
@ianrhile Ай бұрын
Fun. You could also add the index column to the unpivoted data (as shown); add the modulo 3 of the index column (as shown), and then add the integer-divide-by 3 of the same index column. Delete all columns but the value, modulo, and integer-divide columns, and then pivot based on the modulo column. The integer-divide column makes each one unique. (Hopefully that makes sense; it's hard to write this down.) Then delete the integer-divide column, rename the other columns, and change type.
@AccessAnalytic
@AccessAnalytic Ай бұрын
I think I follow 😆
@dmclean3324
@dmclean3324 Ай бұрын
This was my solution as well
@AccessAnalytic
@AccessAnalytic Ай бұрын
Ah yeah after a night’s sleep this made perfect sense. I even did a video using that method a few weeks back 🙄. Good call I’ll add that option into my solution file
@raimundojs9547
@raimundojs9547 Ай бұрын
Thank you for sharing! Here's my contribution: let LstTableToColumns = Table.ToColumns(Source), LstSplit = List.Split(LstTableToColumns, 3), LstTables = List.Transform(LstSplit, each Table.FromColumns(_, {"Name", "Date", "e-mail"})), TbOutput = Table.Combine(LstTables) in TbOutput
@AccessAnalytic
@AccessAnalytic Ай бұрын
Cheers. Would that still work if a 4th or 5th member was added?
@raimundojs9547
@raimundojs9547 Ай бұрын
@@AccessAnalytic Yes, it would. Thank you so much for your response and thank you for all the content you've been sharing.
@Ahmad_Askar
@Ahmad_Askar Ай бұрын
this is very neat
@user-mma173
@user-mma173 Ай бұрын
This is how I would solve it 👍
@AccessAnalytic
@AccessAnalytic Ай бұрын
@@raimundojs9547 - This is a neat solution, I may well do a video showcasing this in the future and giving you a shout out. The slight downside is the members from one group aren't listed together.
@derkgeerdink13
@derkgeerdink13 Ай бұрын
This is absolutely amazing!
@AccessAnalytic
@AccessAnalytic Ай бұрын
⭐️ Thanks very much ⭐️
@BillSzysz1
@BillSzysz1 Ай бұрын
For those who like to play with M, a one-step solution (apart from changing column types).😉 let Source = Table.FromRows( List.Combine( List.Transform( Table.ToRows( Excel.CurrentWorkbook(){[Name="Table1"]}[Content] ), each List.Split(_, 3))), {"Name", "DOB", "Email"} ) in Source
@AccessAnalytic
@AccessAnalytic Ай бұрын
Nice Bill
@TopBam
@TopBam Ай бұрын
Excellent power query solution. In this particular case, I would just use a TOCOL and WRAPROWS formula combo.
@AccessAnalytic
@AccessAnalytic Ай бұрын
Yep agreed, but if the data was a recurring export, or if using Power BI then I’d stick with Power Query
@mnowako
@mnowako Ай бұрын
Amazing! Thank you!
@AccessAnalytic
@AccessAnalytic Ай бұрын
You’re welcome.
@chrism9037
@chrism9037 Ай бұрын
Awesome! PQ is the best
@AccessAnalytic
@AccessAnalytic Ай бұрын
Absolutely
@damiannorton6450
@damiannorton6450 Ай бұрын
Elegant solution, nice!!
@AccessAnalytic
@AccessAnalytic Ай бұрын
Cheers
@kebincui
@kebincui Ай бұрын
Excellent!👍
@AccessAnalytic
@AccessAnalytic Ай бұрын
Cheers
@rameshkunda6775
@rameshkunda6775 Ай бұрын
Nice 👍
@AccessAnalytic
@AccessAnalytic Ай бұрын
Cheers
@williamarthur4801
@williamarthur4801 Ай бұрын
I know it's not very dynamic , but I just selected all columns ; unpivot ; remove "attribute' then ; Table.Combine( List.Transform( Table.Split( Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}), 3 ), (A)=> Table.Transpose(A) )) , you could probably make the page size dynamic and the columns still need naming . Just had a though if you don't use transpose, but table from rows you can renaame; Table.FromRows( Table.ToColumns( A), { "Name", "DOB", "Email"} ) )
@AccessAnalytic
@AccessAnalytic Ай бұрын
Thanks for taking part
@rjbush7955
@rjbush7955 19 күн бұрын
Brilliant! Seen this type of data many times and tried to breakout but got lost after pivoting the first time. My solution is easier; go back to the person and ask them to do it properly 😂
@AccessAnalytic
@AccessAnalytic 19 күн бұрын
Yeah sadly all too often these are the outputs from source systems and ERPs which you often cant alter.
@adrianoschwenkberg6773
@adrianoschwenkberg6773 Ай бұрын
Starting from demotable and a list with column names, you could solve the task thing like this let source = Demodata, grouplist = List.Split(Table.ColumnNames(source),List.Count(groupdef)), groupdef = {"NAME","DOB","EMAIL"}, unstacking = List.Accumulate(grouplist,Table.FromRows({},groupdef),(tbl_out,colName) => Table.Combine({tbl_out,Table.RenameColumns(Table.SelectColumns(source,colName), List.Zip({Table.ColumnNames(Table.SelectColumns(source,colName)),groupdef}))}) ) in unstacking
@adrianoschwenkberg6773
@adrianoschwenkberg6773 Ай бұрын
the approach is : groupdef is a list used for the final columnnames and also by the count as a columncount for the stackingprocess for the outputtable. The stacking is done by list.accumulate which iterates throuh the grouplist and takes the group-columnes , rename them and stack them on the outputtable.
@AccessAnalytic
@AccessAnalytic Ай бұрын
Thanks for taking part.
@jerrydellasala7643
@jerrydellasala7643 Ай бұрын
Love your PQ videos. However, it sounded like the original Table1 data was of group leaders or organizers in the first column [Oname], their DOB [ODOB] and email [OEmail], and the 3 members of those groups. The solution just lumps everyone together. Would love to see a solution similar to yours, but with columns for the organizers. Hope that makes sense!
@AccessAnalytic
@AccessAnalytic Ай бұрын
Thanks I could keep the Group ID and Sequence ID which would then allow filtering by leaders or groups. If you want the groups to go horizontally then maybe a simple transpose might do it. Or pivot based on group ID rather than the header id
@milindkapadia1425
@milindkapadia1425 Ай бұрын
Hi there, I found this video really interesting, and it reminded me of a Power Query challenge I recently worked on. Interestingly, the solution presented in the video is similar to the problem I had, and vice versa. The key difference is that I restricted my data to text type only, as I'm merging columns. Let me share a brief overview of the scenario: Original Table: Sr No Country State City 1 India Maharashtra Mumbai 2 Australia N. South Wales Sydney 3 USA California Los Angeles 4 Canada Ontario Toronto My Solution: I created a solution that dynamically rearranges the table into stacked blocks. The user can choose the number of blocks they want to generate. Here’s how it looks: Sr No_0 Country_0 State_0 City_0 Sr No_1 Country_1 State_1 City_1 1 India Maharashtra Mumbai 3 USA California Los Angeles 2 Australia N. South Wales Sydney 4 Canada Ontario Toronto Key Features: Dynamic Flexibility: The solution is fully dynamic. You can add as many columns or rows as needed, and the table will adjust accordingly. User Input: The user can specify the number of blocks they require. In the above example, I chose to create two blocks. Text Data Restriction: The only limitation is that the data types must be text, as I’m merging the columns. This solution has proven to be very versatile, allowing for easy expansion and reorganization of data based on user needs. However, managing data types while keeping everything in text format has been a unique challenge.
@AccessAnalytic
@AccessAnalytic Ай бұрын
Glad you got a solution working and that Power Query is solving your data issues.
@AccessAnalytic
@AccessAnalytic Ай бұрын
Sounds a little like this : kzbin.info/www/bejne/e6rXc2dpbcd7mpIsi=ATCCECJHxsRqx6OD
@milindkapadia1425
@milindkapadia1425 Ай бұрын
@@AccessAnalytic No, actually, your solution is my question, and my question is your solution. In other words, I used your output table to create what would be your input table.
@milindkapadia1425
@milindkapadia1425 Ай бұрын
This is with reference to your video 'Excel and Power BI Stacking Grouped Columns Challenge".
@mienzillaz
@mienzillaz Ай бұрын
ok, i'm tracking social here on YT to get challenge notifications, but there was none.. i missed this. Anyways, here's my go: let Source = List.Combine(Table.ToRows(Table1)), Custom1 = List.Zip({Source, List.Transform(List.Positions(Source), each Number.RoundDown(_/3,0))}), Custom2 = List.Accumulate({0..((List.Count(Custom1)/3)-1)}, #table({"Name", "DOB", "Email"},{}), (s,c)=> Table.InsertRows(s, c, {[Name= List.Select(Custom1, each _{1}=c){0}{0}, DOB= List.Select(Custom1, each _{1}=c){1}{0}, Email= List.Select(Custom1, each _{1}=c){2}{0}]})) in Custom2
@AccessAnalytic
@AccessAnalytic Ай бұрын
Thanks for taking part
@mienzillaz
@mienzillaz Ай бұрын
@@AccessAnalytic how is my query?
@AccessAnalytic
@AccessAnalytic Ай бұрын
I rarely write M code so seeing it standalone on the screen doesn’t jump out at me as good or bad. I appreciate the skill in the knowledge and use of functions and approaches like list.accumulate. My preference is wherever possible to use the UI as it’s easier to explain and for others to learn.
@mienzillaz
@mienzillaz Ай бұрын
@@AccessAnalytic I learned rather quickly that in my tasks UI is insufficient and inefficient, leading to slow and maintenance hungry data models.
@AccessAnalytic
@AccessAnalytic Ай бұрын
Yes, that’s definitely the right time to delve into the code.
@Ahmad_Askar
@Ahmad_Askar Ай бұрын
sorry for this long code = Table.Combine({Table.SelectColumns(Data, List.FirstN( Table.ColumnNames(Data),3)),Table.RenameColumns(Table.SelectColumns(Data,List.Split( Table.ColumnNames(Data),3){1}),List.Zip({List.Split( Table.ColumnNames(Data),3){1},List.Split( Table.ColumnNames(Data),3){0}})),Table.RenameColumns(Table.SelectColumns(Data,List.Split( Table.ColumnNames(Data),3){2}),List.Zip({List.Split( Table.ColumnNames(Data),3){2},List.Split( Table.ColumnNames(Data),3){0}})),Table.RenameColumns(Table.SelectColumns(Data,List.Split( Table.ColumnNames(Data),3){3}),List.Zip({List.Split( Table.ColumnNames(Data),3){3},List.Split( Table.ColumnNames(Data),3){0}}))})
@AccessAnalytic
@AccessAnalytic Ай бұрын
Thanks for taking part
3 Essential Excel skills for the data analyst
18:02
Access Analytic
Рет қаралды 1,5 МЛН
Excel Dynamic Arrays - Excel Challenge Solution
13:19
Access Analytic
Рет қаралды 2,2 М.
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 9 МЛН
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 17 МЛН
How do Cats Eat Watermelon? 🍉
00:21
One More
Рет қаралды 8 МЛН
7 Advanced PivotTable Techniques That Feel Like Cheating
16:07
MyOnlineTrainingHub
Рет қаралды 38 М.
Default your Date Time Slicer Selection to a Current Period in Power BI!
10:30
What is Power Query?
16:51
Access Analytic
Рет қаралды 46 М.
Try This Instead of the XLOOKUP
10:06
Kenji Explains
Рет қаралды 86 М.
The Excel Trick I Use EVERY DAY (and you should too!)
11:21
MyOnlineTrainingHub
Рет қаралды 137 М.
I Studied Data Job Trends for 24 Hours to Save Your Career! (ft Datalore)
13:07
Thu Vu data analytics
Рет қаралды 228 М.
🚨 YOU'RE VISUALIZING YOUR DATA WRONG. And Here's Why...
17:11
Adam Finer - Learn BI Online
Рет қаралды 171 М.
5 Excel Tricks for Self-Updating Spreadsheets (Files Included)
22:52
MyOnlineTrainingHub
Рет қаралды 124 М.
А ВЫ ЛЮБИТЕ ШКОЛУ?? #shorts
00:20
Паша Осадчий
Рет қаралды 9 МЛН