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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
hnguyen76
Resolver II
Resolver II

Create an array from table (Power Query)

Hi guys!

 

I'm attempting to create an array that has one single input to one single output coming from a table. I currently have a table with multiple columns and I want to map two columns together.

A sample table is supplied below:

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYu3DcAwDMB+0ezBXfaYXl4w/P8bYQANBMiBY0gQJwsE72W6IRFfIVonfINknfEdsnXBDyjWFT+hWit+gVo3/IZm3fEHunXwxPsPqjLnBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t])
in
    Source

 

 

The sample input looks like this:

hnguyen76_1-1664987690377.png



Considering I may have 1000+ records, I want to be able to create an array with the expected output where I select and map Column2 to Column3.


EDIT: Considering all items from Column2 and Column3 will be unique

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYu3DcAwDMB+0ezBXfaYXl4w/P8bYQANBMiBY0gQJwsE72W6IRFfIVonfINknfEdsnXBDyjWFT+hWit+gVo3/IZm3fEHunXwxPsPqjLnBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    ExpectedResult = 
    [
        A = 100,
        B = 200,
        C = 300,
        D = 400,
        E = 500,
        F = 600,
        G = 700,
        H = 800,
        I = 900,
        J = 777
    ]
in
    ExpectedResult

 

 

hnguyen76_2-1664987771225.png

 

How would this be possible? I think I've done it before but I'm currently having a brain fart.

 

1 ACCEPTED SOLUTION
artemus
Microsoft Employee
Microsoft Employee

Here is a modified version of your query that does this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYu3DcAwDMB+0ezBXfaYXl4w/P8bYQANBMiBY0gQJwsE72W6IRFfIVonfINknfEdsnXBDyjWFT+hWit+gVo3/IZm3fEHunXwxPsPqjLnBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    ToRecords = Table.ToRecords(Source),
    Custom1 = List.Accumulate(ToRecords, [], (current, next) => Record.AddField(current, next[Column2], next[Column3]))
in
    Custom1

View solution in original post

2 REPLIES 2
artemus
Microsoft Employee
Microsoft Employee

Here is a modified version of your query that does this.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LYu3DcAwDMB+0ezBXfaYXl4w/P8bYQANBMiBY0gQJwsE72W6IRFfIVonfINknfEdsnXBDyjWFT+hWit+gVo3/IZm3fEHunXwxPsPqjLnBw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    ToRecords = Table.ToRecords(Source),
    Custom1 = List.Accumulate(ToRecords, [], (current, next) => Record.AddField(current, next[Column2], next[Column3]))
in
    Custom1

@artemus Thank you! I attempted to use List.Accumulate but failed lol. This is working perfectly! Cheers!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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