Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Road to Power Query NINJA – 1st STEP

528 views

Published on

2018-11-10 Power Query 秘密特訓「虎の穴」- Power BI 勉強会これから使っていきたい Power Query について。Power Query エディターのUI操作だけでは Power Query の真の力を得ることはできない。スクラッチで書き出すのもよいのだけど、UI操作で出力された関数とかその使われ方を知るだけでも大きく前進ですなのですよ。

Published in: Technology
  • Be the first to comment

Road to Power Query NINJA – 1st STEP

  1. 1. Microsoft MVP - Data Platform / かがたたけし PowerBIxyz takeshi.kagata @powerbixyz Road to Power Query NINJA – 1st STEP Don’t think, Feel. Power Query 秘密特訓「虎の穴」 2018-11-10
  2. 2. #PowerBI #PBIJPどのようなことが起きているのか? let Source = {1 .. Number.Power( 2, 31 ) - 1}, #"Filtered?" = List.Transform( Source, each Number.Power( _, _ ) ), Filter = List.FirstN( #"Filtered?", 10 ) // Filter = List.FirstN( #"Filtered?", each _ <= 10000000000 ) // Filter = List.Select( #"Filtered?", each _ <= 10000000000 ) in Filter
  3. 3. #PowerBI #PBIJP不要な評価はしない List.FirstN( List.Transform( {1 .. Number.Power( 2, 31 ) - 1}, each Number.Power( _, _ ) ), 10 // 先頭 10 アイテム で完了ということが早いうちにわかっている )
  4. 4. 見えるようにする
  5. 5. #PowerBI #PBIJP数式バーは必ず表示
  6. 6. 1000
  7. 7. #PowerBI #PBIJPそもそも プレビュー データ なので
  8. 8. #PowerBI #PBIJP現れないこともある
  9. 9. 50%
  10. 10. #PowerBI #PBIJP条件は反転する
  11. 11. type
  12. 12. #PowerBI #PBIJP見えるものはすべて知るべし
  13. 13. #shared
  14. 14. { } [ ]
  15. 15. #PowerBI #PBIJPリスト – { } 値(value) と その順番を表す { value1, … , valuen } { 1, 2, 3 } = { 1, 2, 3 } // true { 1, 2, 3 } = { 1, 3 } // false { 1, 2, 3 } <> { 1, 3 } // true { 1, 2, 3 } = { 1, 3, 2 } // false { 1, 2, 3 } = { 1, “2”, 3 } // false { 1, 2, { 10, 20 } } = { 1, 2, { 10, 20 } } // true { 1, 2, { 10, 20 } } = { 1, 2, { 10, 20, 30 } } // false
  16. 16. #PowerBI #PBIJPリスト と 演算子など { 1 .. 3 } = { 1, 2, 3} { 3 .. 1 } = { } { “B” .. “D” } = { “B”, “C”, “D” } { 7, 2 .. 4, 1 } = { 7, 2, 3, 4, 1} { 1, 2, 3 } & { 4, 5 } = { 1 .. 5 } List.Combine( { { 1, 2, 3 }, { 4, 5 }, { 0 } } ) = { 1 .. 5, 0 }
  17. 17. #PowerBI #PBIJPItem access – { } { } と { } { 10, 20, 30 }{ 0 } = 10 // true { 10, 20, 30 }{ -1 } // Expression.Error { 10, 20, 30 }{ 3 } // Expression.Error { 10, 20, 30 }{ 3 }? = null // true let idx = 1, item = { 10, 20, 30 }{ idx } in item // 20
  18. 18. #PowerBI #PBIJPレコード – [ ] 定義されたフィールド(field) と その値(value)の組み合わせ [ fieldname1 = value1, …, fieldnamen = valuen ] [Field1=10, Field2=20] = [Field1=10, Field2=20] // true [Field1=10, Field2=20] = [Field2=20, Field1=10] // true [Field1=10, Field2=20] = [Field1=10, Field2=30] // false [Field1=10, Field2=20] = [Field1=10, Field2=20, Field3=30] // false [Field1=10, Field2=20] <> [Field1=10] // true 遅延評価 [Field1=10, Field2=Field1 + 10, Field3=Field1+Field2 ] = [Field1=10, Field2=20, Field3=30] // true
  19. 19. #PowerBI #PBIJPField access と 演算子など [ ] と [ ] [Field1=10, Field2=20][Field1] = 10 // true [Field1=10, Field2=20][Field3] // Expression.Error [Field1=10, Field2=20][Field3]? = null // true [Field1=10, Field2=20, Field3=30][[Field1], [Field2]] = [Field1=10, Field2=20] [Field1=10, Field2=20] & [Field3=30] = [Field1=10, Field2=20, Field3=30] [Field1=10, Field2=20] & [Field2=30] = [Field1=10, Field2=30]
  20. 20. #PowerBI #PBIJPField access – 関数 let FieldName = { "Field1", "Field3" }, Record = [ Field1 = 10, Field2 = 20 ], FieldValues = { Record.Field( Record, FieldName{ 0 } ), Record.FieldOrDefault( Record, FieldName{ 1 } ), Record.FieldOrDefault( Record, FieldName{ 1 }, 0 ) } in FieldValues // { 10, null, 0 }
  21. 21. #table
  22. 22. #PowerBI #PBIJP#table #table( { “column_name1”, …, “column_namen” }, { { value1, … , valuen }, … } ) #table( type table [ column_name1 = type1, …, “column_namen” = typen ], { { value1, …, valuen}, … } )
  23. 23. #PowerBI #PBIJP#table 以外 当然違いがある Table.FromColumns(lists as list, optional columns as any) as table Table.FromList(list as list, optional splitter as nullable function, optional columns as any, optional default as any, optional extraValues as nullable ExtraValues.Type) as table Table.FromRecords(records as list, optional columns as any, optional missingField as nullable MissingField.Type) as table Table.FromRows(rows as list, optional columns as any) as table Table.FromValue(value as any, options as nullable record) as table Record.ToTable(record as record) as table
  24. 24. テーブル と { } [ ]
  25. 25. #PowerBI #PBIJPレコードとリストとテーブル table{n} table{[column_Name = value]} table[column_Name] table[[column_Name1], [column_Namen]] // type table Operator Type table Row { } : Item access record Column [ ] : Field access list
  26. 26. function
  27. 27. #PowerBI #PBIJPUDF 引数なし () => 0 引数あり ( x, y ) => x + y ( x ) => ( y ) => (x + y) オプション引数 ( value1, optional value2 ) => [ Field1 = value1, Field2 = value2 ] データ型 ( x as text, y as number ) as text => Text.Repeat( x, y )
  28. 28. #PowerBI #PBIJPUDF クエリの中で定義する Let fn = ( x ) => x + 10, prm = 10, Result = fn( prm ) in Result レコードで定義もできる let fn = (x) => [result = x + 10][result], prm = 10, Result =fn( prm ) in Result
  29. 29. each _
  30. 30. #PowerBI #PBIJPeach _ は function ex. List.Transfrom( list as list, transform as function ) List.Transfrom( list, each _ + 1 ) ⇩ List.Transfrom( list, (_) => _ + 1 ) ⇩ List.Transfrom( list, (currentItem) => currentItem + 1 ) ⇩ List.Transfrom( list, (currentItem) => let return = currentItem + 1 in return )

×