1
3

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 5 years have passed since last update.

Power BIで複数のExcelシートを結合して読み込む

Last updated at Posted at 2019-08-31

はじめに

  • Power BIのクエリーでExcelファイルを読み込むことができますが、シートが複数ある場合、シートごとにクエリーが作成されてしまいます。
  • 年度ごとにシートが分割している場合など、ひとつのクエリーでまとめて読み込めると便利です。
  • ここでは、複数のExcelシートを結合してひとつのテーブルを作成するクエリーを作成します。

サンプルデータ

Temparature.xlsx
シート:2018

日付 気温(℃)
2018/1/1 8
2018/5/1 19
2018/8/1 29

シート:2019

日付 気温(℃)
2019/1/1 8
2019/5/1 18
2019/8/1 27

Excelファイルの読み込みとシートの結合

  1. Power BIメニュー 「データを取得」より、Excelを選択、Temparature.xlsxを開きます。
    (ここでは、C:\temp\Temparature.xlsxとしています。)
  2. ナビゲータ画面で、読み込むシートのうち一つだけ選択して、データの変換ボタンをクリックします。
  3. クエリーの設定でソースを選択、Excel.Workbook()の2つ目のパラメータ(useHeadders)をTrueに変更します。
    (これにより、シートの1行目を列名として読み込みます。)
Power query
変更前 = Excel.Workbook(File.Contents("C:\temp\Temparature.xlsx"), null, true)
変更後 = Excel.Workbook(File.Contents("C:\temp\Temparature.xlsx"), true, true)
  1. クエリーの設定でナビゲーションを選択し、Table.Combine()を用いて、複数シートを結合する処理に書き換えます。
Power query
変更前 = ソース{[Item="2018",Kind="Sheet"]}[Data]
変更後 = Table.Combine({ ソース{[Item="2018",Kind="Sheet"]}[Data],ソース{[Item="2019",Kind="Sheet"]}[Data] })
  1. 昇格されたヘッダ数のステップは不要のため、削除します。
  2. 必要に応じて、テーブル名を変更します。

Excel_combine.gif

参考

1
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?