-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPart 1 - Using Optional Parameters.pq
More file actions
50 lines (39 loc) · 1.7 KB
/
Part 1 - Using Optional Parameters.pq
File metadata and controls
50 lines (39 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
let
/*
About: Compare different optional parameter types
This is from the post: https://ninmonkeys.com/blog/2024/06/05/power-query-functions-part1-using-optional-parameters
source:
lets call Text.Combine() to test declaring optional parameters
For this version:
- you can pass a null value for a separator
- always requires you pass 2 parameters
*/
Join_Nullable = (texts as list, separator as nullable text) =>
Text.Combine( texts, separator ),
/*
For this version:
- you can pass a null value for a separator
- you can skip the second parameter
- 'optional' parameters are automatically 'nullable',
so you can drop the 'nullable' part
This is how library functions have multiple call signatures
Power Query defines one function
Other languages let you define multiple functions with shared name
Based on the argument types, it'll call a different overloaded function
*/
Join_Optional = (texts as list, optional separator as text) =>
Text.Combine( texts, separator ),
Summary = [
chars = { "a".."h" }, // example array of strings
// this version lets you pass an explicit null value
Nullable_1 = Join_Nullable( chars, ", " ),
Nullable_2 = Join_Nullable( chars, null ),
// but it requires you to pass something. It doesn't let you omit a parameter
Nullable_3 = Join_Nullable( chars ),
// this version lets you pass an explicit null value
// or drop the parameter completely
Join_Optional_1 = Join_Optional( chars, ", " ),
Join_Optional_2 = Join_Optional( chars, null ),
Join_Optional_3 = Join_Optional( chars )
]
in Summary