+ Reply to Thread
Results 1 to 8 of 8

Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    4

    Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    On Excel 2013 here.

    1. I imported data from SQL into PowerPivot.
    2. I have a datetime column, i.e.: "7/31/2013 2:03:51 PM"
    3. I want to create a calculated column which converts that datetime to "of week" in mm/dd - mm/dd format, example for the above datetime: "7/28 - 8/3" as 7/31 fell within that week.

    I don't know if there's a single formula to get this, I'm creating multiple calculated columns to get to the final result. I was able to create two new calculated datetime columns with the first day of that week, and the last day.
    So for the above datetime I have 2 new datetime columns:
    FirstDayofTheWeek: "7/38/2013 2:03:51 PM"
    LastDayofTheWeek: "8/3/2013 2:03:51 PM"

    The next step would be to use =MONTH and =DAY to extract the data to get a final column with nice "mm/dd - mm/dd" format right?

    The problem:
    If I try to execute a =MONTH or =DAY function on a calculated datetime column, PowerPivot errors:
    "Calculation error in column 'Query 1'[]: An arument of function 'MONTH' has the wrong data type or the result is too large or too small."

    The function I'm running to test this is a simple: =MONTH([FirstDayofTheWeek])

    1. The FirstDayofTheWeek column is data type "date"
    2. Same thing happens with the =DAY function
    3. This works perfectly fine in Excel, but seems broken in PowerPivot
    4. This also works fine on the original datetime column that was imported from SQL

    Any ideas? Is there a completely easier way of doing this?

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    Hi,

    I have no experience at all with PowerPivot, so I can't help on that front. But I am going to offer you a simpler solution in Excel, based on the fact that you said
    I'm creating multiple calculated columns to get to the final result.
    This can be achieved with a single cell formula. Assuming your datetime is in A2, use this formula:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Hope this helps somewhat, even if it doesn't answer the question directly

  3. #3
    Registered User
    Join Date
    09-13-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    That works perfectly in Excel but fails in Powerpivot.

    In Powerpivot, this works fine (assuming again that A2 has the datetime):
    =MONTH(A2)
    But this fails with the data type error above:
    =MONTH(A2-1)

    =MONTH or =DAY will fail if I do any operation on the datetime cell that I'm feeding them.

  4. #4
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    Are you searching for any DAX query..
    Please confirm..
    Regards!
    =DEC2HEX(3563)

    If you like someone's answer, click the star to give them a reputation point for that answer...

  5. #5
    Registered User
    Join Date
    09-13-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    Quote Originally Posted by Debraj Roy View Post
    Are you searching for any DAX query..
    Please confirm..
    Not entirely sure. I'm importing the SQL data using a SQL Query (I'm not dumping the entire tables from the SQL server).

  6. #6
    Forum Expert Debraj Roy's Avatar
    Join Date
    09-27-2012
    Location
    New Delhi,India
    MS-Off Ver
    Excel 2013
    Posts
    1,469

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    Sample file with expected output is appreciable..

  7. #7
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    hi thagasa, welcome to the forum. i couldn't replicate your problem. like what Debraj suggested, you could upload a sample file. in Excel, here's an alternative:
    =TEXT(A2-WEEKDAY(A2)+1,"mm-dd")&" - "&TEXT(A2-WEEKDAY(A2)+7,"mm-dd")

    in PowerPivot, you should ensure that your dates are correct. when recognised in Excel & imported to PowerPivot, it should be in Date format. i did 2 dates inside. because my region settings is in DMY, typing MDY will be converted to text. (i did a screenshot in the file). so in the calculated column, your formula should be something like:
    =FORMAT([Date1]-WEEKDAY([Date1])+1,"mm-dd")&" - "&Format([Date1]-WEEKDAY([Date1])+7,"mm-dd")

    change all those in the square brackets to your actual header name
    Attached Files Attached Files

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  8. #8
    Registered User
    Join Date
    09-13-2013
    Location
    USA
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Powerpivot: Convert Datetime to Weekly format (mm/dd - mm/dd)

    Thank you for your example - it does work.

    I set up a new SQL Server Express 2012 on my home PC, created a table with a few datetime rows, imported into PowerPivot and it does work.

    So there's something wrong with the data I imported originally from the SQL server at work, not sure what though. I think I'll start fresh when I get into work and re-import everything.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] i want to change datetime format in excel
    By learner_01 in forum Excel General
    Replies: 29
    Last Post: 04-13-2013, 02:57 AM
  2. i want to change datetime format in excel
    By learner_01 in forum Excel General
    Replies: 1
    Last Post: 04-02-2013, 03:09 AM
  3. Enforce a datetime format and validate it
    By MORRG in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-22-2013, 12:14 PM
  4. Based on a Column datetime value auto calculate and populate a datetime range
    By rajashanmuga in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-22-2010, 04:10 PM
  5. [SOLVED] Custom DateTime Format
    By Sam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-01-2006, 03:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1