5
1

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 1 year has passed since last update.

Power Query workout - culture parameter

Last updated at Posted at 2022-05-21

Power Query の 関数に用意された culture パラメータを明示的に定義するか否かは必要に応じてご自由にということだけれども、少なくとも知っておくが大事。思いもよらないときにあわ、わわわぁってならずに済むでしょ。

評価結果は常に同じではない

異なる評価結果になることがある

Power Query
Date.DayOfWeekName(#date(2022,5,22)) = "日曜日"        // true
Date.DayOfWeekName(#date(2022,5,22)) = "Wednesday"    // true
Date.DayOfWeekName(#date(2022,5,22)) = "domingo"      // true
...
Power Query
Date.DayOfWeekName(#date(2022,5,22), "ja-JP") = "日曜日"      // 常に true
Date.DayOfWeekName(#date(2022,5,22), "en-US") = "Sunday"     // 常に true
Date.DayOfWeekName(#date(2022,5,22), "es-ES") = "domingo"    // 常に true
...

評価結果を得られないことがある

Power Query
Date.From("令和4年5月22日") = #date(2022,5,22)    // true
Date.From("令和4年5月22日")                       // DataFormat.Error
...
Power Query
Date.From("令和4年5月22日", "ja-JP") = #date(2022,5,22)    // 常に true

culture パラメータは optional なので引数を定義しないことが可能。このとき、どのような動作をしているか。
Desktop 環境(Power BI Desktop や Excel)では [Options] / [Query Options]で既定値が設定されている。Power BI Desktop の場合はデータモデルのプロパティ(SourceQueryCulture)として、Excel の場合はファイルのどこかに既定値が保存されているので、Power Query が動作する多くの場合で期待通りの動作をしているはず。
image.png

SourceQueryCulture(DMV:TMSCHEMA_MODEL)
select SourceQueryCulture from $SYSTEM.TMSCHEMA_MODEL

Power Query online(Power BI データフローや Power Platform データフローなど) では [Project options] - [Locale]
image.png

クエリ(Power Query)の評価中にこの既定値を変更することはできないけれども、参照することはできる。

Returns the name of the current culture for the application.
アプリケーションの現在のカルチャの名前を返します。


optional パラメータで culture を定義できる関数

Documentation.Category : Date / DateTime / DateTimeZone / Time

Documentation.Name Documentation.Description
Date.DayOfWeekName 曜日名を返します。
Date.From 指定された値から日付を作成します。
Date.MonthName 月部分の名前を返します。
Date.ToText 日付値のテキスト形式の表記を返します。
DateTime.From 指定された値から datetime を作成します。
DateTime.ToText datetime 値のテキスト形式の表記を返します。
DateTimeZone.From 指定された値から datetimezone を作成します。
DateTimeZone.ToText datetimezone 値のテキスト形式の表記を返します。
Time.From 指定された値から時刻を作成します。
Time.ToText 時刻値のテキスト形式の表記を返します。

Documentation.Category : Number.Conversion and formatting

Documentation.Name Documentation.Description
Byte.From 指定された値から 8 ビット整数を作成します。
Currency.From 指定された値から通貨の値を返します。
Decimal.From 指定された値から 10 進数を作成します。
Double.From 指定された値から Double (倍精度浮動小数点数) を作成します。
Int16.From 指定された値から 16 ビット整数を作成します。
Int32.From 指定された値から 32 ビット整数を作成します。
Int64.From 指定された値から 64 ビットの整数を作成します。
Int8.From 指定された値から符号付き 8 ビット整数を作成します。
Number.From 指定された値から数値を作成します。
Number.FromText 一般的なテキスト形式 (""15""、""3,423.10""、""5.0E-10"") から数値を作成します。
Number.ToText 指定された数値をテキストとして書式設定します。
Percentage.From 指定された値からパーセント値を返します。
Single.From 指定された値から Single (単精度浮動小数点数) を作成します。

Documentation.Category : Table.Transformation

Documentation.Name Documentation.Description
Table.TransformColumnTypes 特定のカルチャを使用して、{ column, type } という形式の型変換を適用します。

Documentation.Category : Text / Text.Conversions from and to text / Text.Transformations

Documentation.Name Documentation.Description
Text.InferNumberType テキストでエンコードされた数値の粒度の数値型を推測します (Int64.Type、Double.Type など)。
Text.Format 書式文字列および引数から書式付きテキストを返します。
Text.From 指定された値からテキスト値を作成します。
Value.FromText テキスト形式の表記から厳密に型指定された値を作成します。
Text.Lower すべての文字を小文字に変換します。
Text.Proper 各単語の最初の文字を大文字にします。
Text.Upper すべての文字を大文字に変換します。
Power Query
Table.SelectRows(
    Record.ToTable(
        Record.RemoveFields(
            #shared,
            Record.FieldNames(#sections[Section1])
        )
    ),
    each
        Type.Is(Value.Type([Value]), Function.Type)
        and List.Contains(
            List.Skip(
                Record.FieldNames(Type.FunctionParameters(Value.Type([Value]))),
                Type.FunctionRequiredParameters(Value.Type([Value]))
            ),
            "culture"
        )
)

思ったこと🙄

転ばぬ先の杖
Excel for the web 上で Power Query で記述したクエリの評価が可能になり始めているけれども、cultureの既定値について理解しておいた方がよさそうだ。
image.png
Excel for the web + Power Query という動作環境では [Regional Format Settings] が culture の既定値に影響する。

その他

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?