LoginSignup
0
3

More than 1 year has passed since last update.

小ネタ:年度とかの計算|Power Query

Posted at

記事には書いたことなかったかも、と思い、取り急ぎメモしました。
二重だったらごめんなさい。

関数コード

ifを使わないのが小さなこだわりです。

年度を求める

fx_yyyy年度
(日付 as date,期末月 as number) as text=>
let x = Date.AddMonths(日付,-期末月)
in  Date.ToText(x,"yyyy年度"),

「yyyy年mm月期」を求める

fx_yyyy年mm月期
(日付 as date,期末月 as number) as text=>
let x = Date.AddMonths(日付,-期末月+12)
in  Date.ToText(x,"yyyy年" & Number.ToText(期末月,"00月期") ),

実行した様子

image.png

理解用クエリ

こんな感じで動作を確認してから関数にしたりします。

let
    期末月 =2,
    日付 =#date(2020,2,29),
    x = Date.AddMonths(日付,-期末月+12), //-----2020/12/29になり、年は維持される。
    result =Date.ToText(x,"yyyy年" & Number.ToText(期末月,"00月期") )
in
    result

テスト環境

Microsoft365のExcel(バージョン2104)64bit
Power Query:2.92.944.0 64ビット

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