Versions Compared
Version | Old Version 7 | New Version Current |
---|---|---|
Changes made by | ||
Saved on |
Key
- This line was added.
- This line was removed.
- Formatting was changed.
...
Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
By the end of this chapter you will be able to:
- Create macros
- Use macros
Creating macros
...
Macros are used to create reusable expressions. They can be thought of as, the ability to write bespoke functions. Macros can optionally take in a number of parameters to use within its expression:
- Find
in the repositoryInsert excerpt _macros _macros nopanel true - Right-click and select
...
Add MacroInsert excerpt _addIcon _addIcon nopanel true - Configure the macro:
- Name:
NumOfWeeks
- Minimum Parameters:
2
- Maximum Parameters:
2
- Expression: create an expression to work out the number of weeks - as a whole number – between two dates
Use the
- Name:
...
...
Expand title See Completed Expression do(
// Create variables from incoming parameters
$Date1 = $args[1],
$Date2 = $args[2],
// Get the difference in time between the two dates
$dateDiffMilliSecs = dateDiff( $Date2, $Date1 ),
// Round the answer into whole weeks
round($dateDiffMilliSecs/(1000*60*60*24*7), 0 )
)
- Press
to save your new macroInsert excerpt _finish _finish nopanel true
Using Macros
- Create a new model:
Try Macros
- Drag the
...
- table
MC Macro Terminated Customers
on to your model- This contains some key dates for terminated customers: the signup date; the date that the customer terminated their service; the date that the final debt on the customer's account was cleared
- Add
...
for:Insert excerpt _attributes _attributes nopanel true - the number of weeks between signup and termination
- the number of weeks between termination and the final debt being cleared
In each case, use your macro to calculate the number of weeks between the two dates
Expand title
...
How? Expression:
NumOfWeeks(_out.SIGNUP_DATE,_out.TERMINATION_DATE)
Expression:
NumOfWeeks(_out.TERMINATION_DATE,_out.DEBT_CLEARED)
- Run the table
MC Macro Terminated Customers
to test your new attributes