1
2

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

PowerQuery: Excel で相対パスで動かしたい場合

Posted at

背景

昔必要になった際のメモ

対象フォルダ以下に対して処理したい場合に、相対パスが欲しくなる時用。

概要

  • Excel 関数で 相対パスを取得
  • Table で Power QUery に渡して利用

詳細

Excel 関数で相対パスを取得

image.png

現在パスの取得
LEFT(CELL("filename",A1),FIND("[",CELL("filename",A1))-2)

CELL() 関数で、フルパスを取得して、ファイルの保存フォルダを取得

image.png

A1 形式を利用しているので、このまま利用する場合は、以下設定を。
R1C1 形式に変換すれば動くかも(未検証)
image.png

Table 化して、Power Query で

image.png

取得した結果を使って、以下のようにして、利用するだけ

image.png

分解してみると・・

普通にテーブル範囲を取り込んだ状態
image.png

テーブルに一点だけなので、一つ目ってことで、{0} を付加
image.png

文字列として使う為に、[CurrentPath] を指定
image.png

あとがき

ローカルで Excel を使うことは減ってはいるけれど、Power BI の前段階で Excel-Power Query を教えることはまだ多い。
そんな時、人と共有しやすくする相対パス利用はまだまだ需要があるみたいですね。

keyword

how to use relative path in Excel Power Query

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?