Forum Discussion
Converting Unix timestamp from Stripe API to Date/Time
- 10 years ago
Well, if it is a Unix timestamp, then it is the number of seconds from 1/1/1970 (UTC). So something like this calculated column should suffice:
UTCTime = VAR UnixDays = [UnixTime]/(60*60*24) RETURN (DATEVALUE("1/1/1970")+UnixDays)Basically, convert the number of seconds to the number of days and then add it to the date value of 1/1/1970. Essentially, the same thing you would do in Excel.
Soooo...that's a very good question. One perspective is that it is always the right choice to do as much in "M" as possible as this is more efficient processing-wise. Another perspective on this is that if you are going to end up having to use DAX, then use all DAX, otherwise you are maintaining code in two different languages. This would be like writing a program half in C# and half in java and half in PHP for example. Nobody wants to maintain that. Yet a third perspective is that DAX has, by far, the lower learning curve, especially if coming from Excel so most people start with DAX and then eventually pick up M and start to do more things in M over time.
My best practice, use what works for you given your comfort level with the language and use the right tool for the job. Pivoting tables, and really complex manipulations of the data, that's a job for "M". Adding a custom column, that depends on the formula. Some things are a cake walk in DAX and next to impossible in "M" and vice versa. Adding a custom measure, that's DAX all day long.
I would recommend reading this:
http://www.powerpivotpro.com/2014/10/5-common-mistakes-made-by-self-taught-dax-students/
For people who want to do this same function in M, its answered in other posts, but want to combine both options here
#datetime(1970, 1, 1, 0, 0, 0) + #duration(0, 0, 0, [UnixTime])