0
0

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.

Azure Data Factory - Data Flow で月初を取得する方法

0
Posted at

はじめに

Azure Data Factory や Azure Synapse Pipeline の Data Flow (GUIとノーコードでデータ加工できるツール)を使ってデータ集計や予測モデル用のデータ加工をするときのテクニックを整理しています

やりたいこと

日次データを月別に集計したいケースがあると思いますが、そのとき日付データから月単位の値を作成すると思います
'YYYYMM' とか 'YYYY-MM-01' とか
このときに日付値で保持していた方が日付計算の関数が利用できたり、BIで可視化する際に日付軸として扱いやすいので、筆者は日付値の'YYYY-MM-01'で作成するようにしてます

方法

日付項目から月初('YYYY-MM-01')を作成する方法はいくつかありますが、筆者は下記のやり方で算出してます
派生列(Derived column)モジュールで列の追加をして式ビルダーにて下記の関数で算出
addMonths(lastDayOfMonth({日付項目}),-1)+1
やっていることを解説しますと
①lastDayOfMonth関数を使って対象日付の月末を算出し
 日付項目='2022/01/20'の場合は'2022/01/31'
②①の日付をaddMonths関数を使って1ヶ月前にして '2022/01/31'⇒'2021/12/31'
③②の日付に1日足す '2021/12/31'⇒'2021/01/01'
Dataflow03_01.PNG

参照

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?