Transpose and separate data

Tigerexcel

Active Member
Joined
Mar 6, 2020
Messages
421
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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

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
421
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,169
Messages
5,509,574
Members
408,743
Latest member
1245585

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top