LoginSignup
0

posted at

【Power Apps】結合 (JOIN) してデータを取得する

【Power Apps】結合してデータを取得する

Power Apps で結合する方法です。

テーブル準備

例として以下のようなテーブルデータを準備します。

col商品マスタ

商品ID 商品名 単価 産地
1 りんご 120 青森
2 みかん 80 愛媛
3 マンゴー 200 沖縄

col注文テーブル

注文ID 商品ID 注文日 数量
20230130 1 2023/01/30 12
20230131 2 2023/01/31 30
20230201 4 2023/02/01 4
20230202 1 2023/02/02 12

コレクション生成

App の OnStart でコレクションを作っておきます。

ClearCollect(
    col商品マスタ,
    { 商品ID: 1, 商品名: "りんご", 単価: 120, 産地: "青森" },
    { 商品ID: 2, 商品名: "みかん", 単価: 80, 産地: "愛媛" },
    { 商品ID: 3, 商品名: "マンゴー", 単価: 200, 産地: "沖縄" }
);

ClearCollect(
    col注文テーブル,
    { 注文ID: 20230130, 商品ID: 1, 注文日: Date(2023, 01, 30), 数量: 12 },
    { 注文ID: 20230131, 商品ID: 2, 注文日: Date(2023, 01, 31), 数量: 30 },
    { 注文ID: 20230201, 商品ID: 4, 注文日: Date(2023, 02, 01), 数量: 4 },
    { 注文ID: 20230202, 商品ID: 1, 注文日: Date(2023, 02, 02), 数量: 12 }
)

左外部結合 (LEFT OUTER JOIN)

同名の [商品ID] 列が存在していると Ungroup 関数でエラーになるので、追加したい列を ShowColumns 関数で指定します。

Ungroup(
    AddColumns(
        col商品マスタ As a,
        "group",
        ShowColumns(
            Filter(
                col注文テーブル As b,
                a.商品ID = b.商品ID
            ),
            "注文ID",
            "注文日",
            "数量"
        )
    ),
    "group"
)

内部結合 (INNER JOIN)

左外部結合 で取得したコレクションを空の行を Filter します。

Filter(
    Ungroup(
        AddColumns(
            col商品マスタ As a,
            "group",
            ShowColumns(
                Filter(
                    col注文テーブル As b,
                    a.商品ID = b.商品ID
                ),
                "注文ID",
                "注文日",
                "数量"
            )
        ),
        "group"
    ) As c,
    !IsBlank(c.注文ID)
)

参考サイト

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
What you can do with signing up
0