Transpose and separate data

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
427
Office Version
365, 2019
Platform
Windows
Hi, I'm new to Power Query. I tried to solve this problem and it seems worked well, post for your reference.
Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Index =Table.AddIndexColumn(Table.UnpivotOtherColumns(Source, {"TITLE", "NAME"}, "Attr", "Value"),"Index",1),
    fx=(x)=>
        Text.From(
            List.Count(
                List.PositionOf(Table.SelectRows(Index,each [Index]<=x{4} and [TITLE]=x{0} and [NAME]=x{1})[Attr],x{2},2))),
    DeleteCol = Table.RemoveColumns(Table.AddColumn(Index,"Helper",each _[Attr]&"."&fx(Record.ToList(_))),{"Attr", "Index"}),
    Pivot = Table.Pivot(DeleteCol, List.Distinct(DeleteCol[Helper]), "Helper", "Value")
in
    Pivot
View attachment 19049
Transpose and separate data.xlsx
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1TITLENAMESubjectGradeScoreTITLENAMESubject.1Grade.1Score.1Subject.2Grade.2Score.2Subject.3Grade.3Score.3Subject.4Grade.4Score.4Subject.5Grade.5Score.5Subject.6Grade.6Score.6
2BusinessTomABC1010D72ArtsFredABC6010N4ABC6020N3ABC6090N3ABC6120N3
3BusinessTomABC1020D75ArtsPeterABC4160C60ABC4390P52ABC4140N38ABC4270N47
4BusinessTomABC1110C63BusinessBertABC2020D73ABC2040N42ABC2050D73ABC2080N44
5BusinessTomABC1690D71BusinessTomABC1010D72ABC1020D75ABC1110C63ABC1690D71ABC1500N45ABC1700P51
6BusinessTomABC1500N45EngineeringJackABC4160C62ABC4390D73ABC4490D72ABC4140C62
7BusinessTomABC1700P51
8EngineeringJackABC4160C62
9EngineeringJackABC4390D73
10EngineeringJackABC4490D72
11EngineeringJackABC4140C62
12ArtsPeterABC4160C60
13ArtsPeterABC4390P52
14ArtsPeterABC4140N38
15ArtsPeterABC4270N47
16ArtsFredABC6010N4
17ArtsFredABC6020N3
18ArtsFredABC6090N3
19ArtsFredABC6120N3
20BusinessBertABC2020D73
21BusinessBertABC2040N42
22BusinessBertABC2050D73
23BusinessBertABC2080N44
Sheet1
Very nice Shaowu, that is very efficient, you've achieved a lot in just a few steps!
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

shaowu459

Active Member
Joined
Apr 26, 2018
Messages
476
Office Version
365
Platform
Windows
Very nice Shaowu, that is very efficient, you've achieved a lot in just a few steps!
:giggle:thanks for the feedback:giggle: I began to learn Power Query about one month ago and I found it very interesting and enjoyed solving problems with this tool. I just learned another trick using List.Accumulate and I'd like to share to you😄

transform consecutive numbers like 1,2,3,4 to 1-4 and 7,8 to 7-8.

1595952097926.png
 

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
427
Office Version
365, 2019
Platform
Windows
:giggle:thanks for the feedback:giggle: I began to learn Power Query about one month ago and I found it very interesting and enjoyed solving problems with this tool. I just learned another trick using List.Accumulate and I'd like to share to you😄

transform consecutive numbers like 1,2,3,4 to 1-4 and 7,8 to 7-8.

View attachment 19151
Thank you Shao, I've not heard of List.Accumulate until now, it would appear that it's a very versatile function.
 

CA_Punit

Well-known Member
Joined
Nov 18, 2019
Messages
866
Office Version
365
Platform
Windows
:giggle:thanks for the feedback:giggle: I began to learn Power Query about one month ago and I found it very interesting and enjoyed solving problems with this tool. I just learned another trick using List.Accumulate and I'd like to share to you😄

transform consecutive numbers like 1,2,3,4 to 1-4 and 7,8 to 7-8.

View attachment 19151

Thanks for Sharing,, While Practicing I got how to do with formula also.

Book1
JKLMNOPQ
151,2,3,8,9,10,15,1611-3,8-10,15-16
162
173
188
199
2010
2115
2216
23
Sheet9
Cell Formulas
RangeFormula
M15:M114M15=IFERROR(TRIM(MID(SUBSTITUTE(J15,",",REPT(" ",LEN(J15))),(ROW(A1:A100)-ROW(A1))*LEN(J15)+1,LEN(J15)))+0,"")
P15P15=TEXTJOIN(",",TRUE,INDEX($M$15:$M$22,AGGREGATE(15,6,UNIQUE((((M15:M22)-INDEX($M$15:$M$22,ROW(A1:A10)+1)=-1)*ROW(A1:A10)=0)*ROW(A1:A10)),{1;2;3})+1)&"-"&INDEX($M$15:$M$22,IFERROR(AGGREGATE(15,6,UNIQUE((((M15:M22)-INDEX($M$15:$M$22,ROW(A1:A10)+1)=-1)*ROW(A1:A10)=0)*ROW(A1:A10)),{2;3;10}),COUNT($M$15:$M$22))))
Dynamic array formulas.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,626
Messages
5,512,478
Members
408,899
Latest member
cve60069

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top