LoginSignup
1
4

More than 1 year has passed since last update.

Power QueryのM言語でテーブルから行番号と列名を使って値を取得する

Last updated at Posted at 2021-12-09

テーブルから値を取得する方法。

以下のとおり。

テーブル→リスト(列)→値
let
    table = どこかで作ったテーブル
    list = table[column],  //`column`は列名で、日本語だろうが、間にスペースがあろうが、ダブルクォーテーションで囲う必要はない
    value = list{#}        //`#`は行番号で、0から始まる数字(プレビューは1からなのでずれる)
in
    value
テーブル→レコード(行)→値
let
    table = どこかで作ったテーブル
    record = table{#},        //`#`は同上
    value = record[column] //`column`は同上
in
    value

図で書くとこんな感じ:

\begin{matrix}
     &    &  \begin{matrix}テーブル\\ table \end{matrix}  & & \\
     & {\LARGE ↙} & & {\LARGE ↘} & \\
    \begin{matrix}リスト\\ table[column] \end{matrix} & & & &     \begin{matrix}レコード\\ table\{\#\} \end{matrix}\\
    & {\LARGE ↘} & & {\LARGE ↙} &\\
    & &\begin{matrix}値\\ table[column]\{\#\}\\ table\{\#\}[column] \end{matrix} & &\\
\end{matrix}

また、ある列に関する条件が合致する行がひとつの場合は以下で行を取得可能:

テーブル->行
let
    table = どこかで作ったテーブル
    record = table{[column1="ある値1", column2="ある値2"]}
in
    record
1
4
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
4