How to create a Today metric (similar to Today() in Excel)

  • 11 January 2024
  • 0 replies
  • 111 views

Userlevel 4
Badge +6

Calculate the current date in Pigment

 

Excel function: Today()

 

For some use cases it can be a requirement to calculate something based on the current date. With the recently released Pigment Metric to Metric import functionality we can now build a metric in a Pigment application that will hold today's date and will update automatically each night. 

 

In this article we will explain how to set this up. You can use the final metric for multiple calculations or as a variable to automatically update the page selectors of your boards. A few examples of use cases are listed below: 

  • Update page selector with a dynamic variable connected to the Today metric
    • From the Today metric you can calculate a current month metric and connect that to your application variables. This will enable you to automatically update board page selectors or calculated items which will always show the current month.
  • Calculate with time
    • In some use cases you want to see a reference to today. For example you would like to show how much you are overdue on a project end date or you want to calculate the amount of days that an employee is working. With the today metric you can calculate this easily and it will update automatically.
  • Filter in datasets
    • Another use case is to filter datasets. Maybe you only would like to see the most recent 3 months of transactions? Leveraging the today metric will allow you to do that without any manual interference!

 


 

How to set this up:

 

  1. Create a dimension called Import and add 1 item called “1”
    • Note that you can also use any other existing dimension as long as it has 1 item and will not change. We need this dimension to be able to run an import in step 4 as we can’t import into a metric without any dimensions.

 

wXD9LGUyinnJppNHlovNTdJwUpvwRCoLPReEX6YamaT8__eYQbG3OJh1946Ku0AYrTkn6FJXcSN-w6p6eZevvqmK8BNWuyMcQ_Ss7YuC2EnA6eCSmaOn-yRTj63DmSD1fgEGz1jUnHJNWwjzOReEXHA


 

  1. Create a date formatted metric with the name Today and add the dimension Import to it
    • Fill the cell manually with yesterday's date (we will update the date to today's date in step 4)


 

09OjfPwcoiQHeNCu2lgY__vvywz9lJThC1udv3Xgk8EtX_rc0eX66RBPlPZnWxBIuajCmaqHHrFMxEfqRPkrpDyR4Ih1eMVIv9HqwradPHS27F3OwIbsO0bY7yqmYvaazik827agx4uOoCUlf3BFxpE


 


 

  1. Create a date formatted metric with the name Tomorrow and add the dimension Import to it
    • Apply the following formula: Today +1 

 

QgRv_EnmBxGiGNU50jVdznW10r5kgFgzqVU1ocp8heevbGBq7Gizg8l9nxbLxh_pLABcPH3HR3jDLjXBj72teb_WlGr67KadHHhHlvCkH6AYz5B9t3c2E291kSch5iGY1y7_jyRDYsTnQlNqCOvhjZ4


 

  1. Set-up a Metric to Metric import from Tomorrow -> Today
    • Make sure you save the import configuration and choose to clear existing values


 

hB7J3LpveFm_cwGSa1yU8j46mG4KUePdxoImqbJYXDATO8eLhYQtuiFAn9vycIpOkkAyct8F42jldhVJMNJ3P6n-ZhWCbhmrbU0CviDnBvQkRonNjzXEPr27liM1kITARU_9MG7MhwOMAiTPFHRm8l8


 

  1. Schedule the import to run every night at 00.01 on your preferred timezone.
    • Set yourself or any other admin user as the designated user to receive an email in case there is an error message on the import

 

Hz5Namp6oXbvRGEP64TtDvqn-kTj5R8lduCi_Q8aIGSv9MR4mVta4xqMbA1x44USL9O9IRXCfyQDyPTpghEB-rVtR_cvRC7UxEDNucXPVbYxSM9IfK6tlbu0xZwrNm2Hpse9pKFQB0O4Acrtba79iV0

 

All set! Now your today metric will always contain the current date and you can build any type of calculation or report based on it! If you want to reference your today metric in another block make sure you remove the Import dimension by using the REMOVE modifier in your formula. An example below shows how to calculate the current month by using the formula Timedim: timedim(Today [remove first: import], month)



 

Pw_OxwlNg8GsqH5yAOwVzyBxE1Z64xAYNtq83U6Y8nwxQsCw430wDkkC9MejYAhKXW7qSHtNVKmy0uUmrtfSHCCbmGAUweMN5iarsXIZ52bHqHxwmfRhZCzD-E3oTofYlQ4jJsuFaJ8nU_FNYZjGFKA


 


0 replies

Be the first to reply!

Reply