Best Of
Re: Checkbox Selector not showing all values?
yes thank you Mark. No idea why it works but it works so thank you!
How to Aggregate DateTime Differences
Scenario
Transactional product tables often have multiple date columns that need to be compared and aggregated. Many reports will require the average time between dates to track the overall progress, for example a customer transaction table might have the following date fields:
· “purchase_date”
· “ship_date”
· “delivery_date"
Understanding the time between DateTime columns and aggregating those times to a total is a common way to track the progress, but by design, DateTime differences will result in a DateTime filed and not a calculatable integer.
Beast Mode Sample Code:
This code works on the DomoStats Activity Log dataset and is subtracting the Batch date from the Event date.
Beast Mode Sample Code Results:
The results are displayed in Hour:Minute:Second:Millisecond, but the column is still a DateTime field and not a calculatable integer.
Solution
- Convert the DateTime columns to seconds. This changes the datatype to integer so it can then be calculated.
- Perform the calculation on the integer.
- Convert the seconds integer back to a DateTime datatype.
Beast Mode Example:
Here are a few Beast Mode code examples that use the above steps. These Beast Mode codes work with the DomoStats Activity log dataset.
Total Event Time in Seconds:
First, convert the DateTime to seconds and sum the results.
I am using the UNIX_TIMESTAMP and FROM_UNIX functions for their speed and simplicity. The TIME_TO_SEC and SEC_TO_TIME are popular options as well, but might need additional functions to get the format as needed.
SUM(UNIX_TIMESTAMP(`Event_Time`))
Time difference in Seconds:
Repeat the steps for each DateTime field and preform the calculation.
The "Time Difference in Seconds" is the Numerator for the "Average Time per Event" calculation.
SUM(UNIX_TIMESTAMP(`_BATCH_LAST_RUN_`)) - SUM(UNIX_TIMESTAMP(`Event_Time`))
Total Events:
The "Total Events" count is the Denominator for the "Average Time per Event" calculation.
COUNT(`Event_Time`)
Average Time per Event:
This function is set to format the time in Day:Hour:Minute:Second.
FROM_UNIXTIME((SUM(UNIX_TIMESTAMP(`_BATCH_LAST_RUN_`)) - SUM(UNIX_TIMESTAMP(`Event_Time`))) / COUNT(`Event_Time`), '%d:%h:%i:%s')
Outcome & Observations
Using this method you can now calculate the difference between DateTime columns and aggregate those times up to a total.
JedP
Re: Calculated Column using Current Date
I would use the DateDiff function to do this. Something like this:
case when DATEDIFF(CURRENT_DATE(),Credit Release Date) <6 THEN 'Recent' ELSE 'No' END
Returns the number of days between two dates from datetime values.
DATEDIFF(CURRENT_DATE(), 'lastmoddate')
Re: Calculated Column using Current Date
@JenHarrison It looks like your missing a ) after CURRENT_DATE which is resulting in the syntax error. Though you will probably want to use the DATEDIFF() function instead as in your current beastmode it's just subtracting the day of the month so you might run into situations where it results in a number greater than 6 but it is actually within 6 days. DATEDIFF() will give you the number of days between two dates.
VIDEO TUTORIAL: How to calculate Percentile Rank (for A/B testing)
Percent ranking answers what "% of values were less than Y." Kudos to @GrantSmith for the question.
This is useful for comparing test results in two populations. Imagine 67 respondents tested 75% or les whereas in group B 99 respondents scored 75% or less.
To calculate % rank, you calculate the rank and divide each rank by the count of values.
Here's the video tutorial on 3 different ways to calculate the result (using MagicETL, Analyzer and Dataset Views)
Re: REGEX Extracting Names
Are you simply looking to just remove the open and close brackets and the double quotes?
Re: REGEX Extracting Names
I would use the formula tile and use the replace function multiple times to remove those characters.
Something like this:
REPLACE(REPLACE(REPLACE(fieldname,'[',''),']',''),'"','')








