見出し画像

2023年1月10日 よく使うM言語 日付

パワークエリを使用する際、日付を取得したいときがあると思います。

しかし、いつも日付が日付データに置き換えられる状態で記述されているわけではありません。

YYYYMMDDの形できれば、あとは型を日付にするだけとなります。

いかにYYYYMMDDの形にしていくかが、大事になります。
一番の厄介なパターンは、元データの月や日が1や2のように一桁になっているときです。

私がよく使うのは以下コードです。

if Text.Length([月])=2 then [月] else "0"&[月]

日でも同じです。

これさえできればあとは、年月日を合体させYYYYMMDDの完成です。

When using a power query, there are times when you want to retrieve a date.

However, dates are not always written in a way that they can be replaced with date data.

If you have a YYYYMMDD format, all you need to do is change the type to date.

The key is how to make it into YYYYMMDD. The most troublesome pattern is when the month or day of the original data is a single digit, such as 1 or 2.

I often use the following code.

The same is true for day.

Once this is done, the date and time can be combined to complete YYYYMMDD.



この記事が気に入ったらサポートをしてみませんか?