top of page

Excel Arena

This is the place, where we can test the boundaries of Excel functions.

Alphabetical Triangle based on given number of Rows - Excel and M-Code

Today we are going to discuss about numerous methods in Excel and Power Query to create alphabetical triangle based on given number of rows.

Excel Solutions:

Method-1:

=LET(r,SEQUENCE(A1),c,TOROW(r)-1,IF(r>c,CHAR(MOD((r*(r-1)/2)+c,26)+65),""))


Method-2:

=MAKEARRAY(A1,A1,LAMBDA(r,c,IF(r>=c,CHAR(MOD(r*(r-1)/2+c-1,26)+65),"")))


Method-3:

=IFNA(CHAR(REDUCE(65,SEQUENCE(A1,,2),LAMBDA(a,v,VSTACK(a,MOD(SEQUENCE(,v,v*(v-1)/2),26)+65)))),"")


M-Code:

Method-4:

let

Source = 15,

Result = Table.FromRows(Table.ToColumns(Table.FromColumns(List.Transform({1..Source}, (f) => List.Transform(List.Numbers(f * (f-1)/2 ,f,1), (x) => Character.FromNumber(Number.Mod(x,26) + 65))))))

in

Result


Method-5:

let

Source = 15,

Result = Table.FromRows(Table.ToColumns(Table.FromColumns(List.Generate(() =>

[a = {Character.FromNumber(65)}, n = 2], each [n] <= Source + 1, each [a = List.Transform(List.Numbers( [n] * ([n] - 1)/2 , [n], 1), (f) => Character.FromNumber(Number.Mod(f,26) + 65) ) , n = [n] + 1], each [a]))))

in

Result


Method-6:

let

Source = 15,

Result = Table.FromRows(Table.ToColumns(Table.FromColumns(List.Accumulate({2..Source},{{"A"}}, (s,c) => s & {List.Transform(List.Numbers( c * (c-1)/2,c,1), (f) => Character.FromNumber( Number.Mod(f,26) + 65))}))))

in

Result

Comments


  • Facebook
  • Twitter
  • LinkedIn

©2022 by Excel with Excel. Proudly created with Wix.com

bottom of page