1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Power Query] 1列に積み重なったデータを表形式にするベストプラクティスは? (3) List.Split → Table.FromRows

Last updated at Posted at 2023-07-30

※この記事は 2023/7/22 に作成しました。
※オプションで、「地域の設定」の「クエリステップ」は、「常に英語」に設定されています。日本語で使用している場合は、各自環境で作成されるコードに読み替えてください。

以下のように、複数の項目が1列になっているデータをテーブルにする方法の3番目です。

Index

解法3: 3行ごとにリストを作成してテーブルを作成

 解法2では、3行ごとにテーブルを作成していましたが、今回は List.Split でリストを作成します。

List.Split

 数式バーの右の「fx」を押し、数式バーにList.Split関数を入力します。

構文
List.Split(
    list as list, 
    pageSize as number
) as list

 第一引数の対象となるデータはリストにする必要がありますので、テーブル名の後に列名を[]で囲ってリスト形式にしています。Table.ToList関数を使って、List.Split(Table.ToList(Source), 3)とすることもできます。第二引数は、区切るサイズを指定しますので、項目数となる3を入力しています。返される値は入れ子になったリストになります。

Table.FromRows

 数式バーの右の「fx」を押し、数式バーにTable.FromRows関数を入力します。

 Table.FromRows関数は、入れ子になったリストをテーブルに変換します。

構文
Table.FromRows(
    rows as list, 
    optional columns as any
) as table

ソースコード

let
    Source = Table.FromColumns(
        {
            Lines.FromBinary(
                File.Contents("**File Name**"), 
                null, 
                null, 
                932
            )
        }
    ),
    Custom1 = List.Split(
        Source[Column1], 
        3
    ),
    Custom2 = Table.FromRows(
        Custom1
    )
in
    Custom2
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?