Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Duplicate a column with power query

Hi,

 

I have data like this : 

 

Column1 | Column 2 | Column 3

a                   d               g

b                   e               h

c                   f                 i

 

 

I want this : 

 

a      d        g

a      e        g

a      f         g

a      d       h

a      e       h

a      f       h

a      d       i

a      e       i

a      f       i

b      d      g

b      e      g

...

...

 

Is it possible in Power BI? (or excel)

Thanks !

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Easy Cartesian product regardless of count of columns, for instance, 4 columns

CNENFRNL_0-1644514606837.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoB4nQgzlKK1YlWSgKyUoE4A4izwSLJQFYaEGcCcY5SbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    Cols = Table.ToColumns(Source),
    Cartesian = Table.FromRows(
        List.Accumulate(List.Skip(Cols), List.Transform(Cols{0}, each {_}),(s,c) => List.TransformMany(s, each c, (x,y) => x & {y}))
    )
in
    Cartesian

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

Easy Cartesian product regardless of count of columns, for instance, 4 columns

CNENFRNL_0-1644514606837.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUUoB4nQgzlKK1YlWSgKyUoE4A4izwSLJQFYaEGcCcY5SbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    Cols = Table.ToColumns(Source),
    Cartesian = Table.FromRows(
        List.Accumulate(List.Skip(Cols), List.Transform(Cols{0}, each {_}),(s,c) => List.TransformMany(s, each c, (x,y) => x & {y}))
    )
in
    Cartesian

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@Anonymous , I would advise crossjoin in DAX

new table =

Crossjoin(Table, Distinct(Table[Column3]) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.