Pivot Table: Date + Weekly Display

  • Pivot Table: Date + Weekly Display

    Posted by DSC Communities on June 29, 2020 at 8:07 pm
    • Ajay Kamath

      Member

      June 29, 2020 at 8:07 PM

      Hi Guys,

      I have a Date field and customer wants below to be done.

      Display current date to next 5 days and then display the remaining in terms of weeks as below.. is there a way or any other approach available to implement this feature. Please suggest

      ——————————
      Ajay Kamath

      ——————————

    • Steve James

      Member

      June 30, 2020 at 5:13 AM

      Assuming you have a valid Date table with a column called Date, add the following column to the Date table and use it in the column field of your pivot table:

      Date Band =
      VAR _Today =
          TODAY ()
      VAR _RelDate =
          INT ( 'Date'[Date] - _Today ) + 2
      VAR _RelWeek =
          TRUNC ( DIVIDE ( _RelDate, 7 ), 0 )
      VAR _RelDateDay =
          FORMAT ( 'Date'[Date], "mm" ) & "/"
              & FORMAT ( 'Date'[Date], "dd" ) & "/"
              & YEAR ( 'Date'[Date] )
      VAR _RelWeekStart =
          FORMAT ( _Today + ( _RelWeek - 1 ) * 7 + 5, "mm/dd/yyyy" )
      VAR _RelWeekEnd =
          FORMAT ( _Today + ( _RelWeek - 1 ) * 7 + 11, "mm/dd/yyyy" )
      VAR _RelDateWeek = _RelWeekStart & " - " & _RelWeekEnd
      VAR _Label =
          IF ( _RelWeek = 0, _RelDateDay, _RelDateWeek )
      RETURN
          _Label
      ?

      ——————————
      Steve James
      Director
      ——————————
      ——————————————-

    • Ajay Kamath

      Member

      July 2, 2020 at 6:54 PM

      Hi Steve,

      Thanks much for your reply..i almost got it working in my report using your formula today but ended up getting a different requirement from client.

      it has to be Display current date to next 5 days and alsoĀ Previous 5 daysĀ  and then display the remaining in terms of weeks as below..Ā 

      Can u please help on this too.

      Thanks again

      ——————————
      Ajay Kamath
      T5J 3M5
      ——————————
      ——————————————-

    • Steve James

      Member

      July 3, 2020 at 6:23 AM

      Hi Ajay

      I created a temp Power BI desktop file to work up my solution, but I’m afraid I’ve deleted that now. However, you could experiment with the above column definition to see whether you can achieve what you want.

      Firstly, the definition of _Label tests whether _RelWeek is 0. If you need to report at a day level for the previous week as well, that would have a _RelWeek of -1, so you could amend that part of the formula to test for 0 or -1. Secondly, the definition of _RelDate adds 2 to the current date to account for the fact that your first week (_RelWeek = 0) contains 5 days rather than 7. You may need to amend this, or duplicate the logic for dates in the past.

      Bearing this in mind, you might want to try something like the following. I can’t guarantee that this will work though, as I haven’t been able to test it:

      Date Band =
      VAR _Today =
          TODAY ()
      VAR _RelDate =
          IF (
              'Date'[Date] >= _Today,
              INT ( 'Date'[Date] - _Today ) + 2,
              INT ( 'Date'[Date] - _Today ) - 2
          )
      VAR _RelWeek =
          TRUNC ( DIVIDE ( _RelDate, 7 ), 0 )
      VAR _RelDateDay =
          FORMAT ( 'Date'[Date], "mm" ) & "/"
              & FORMAT ( 'Date'[Date], "dd" ) & "/"
              & YEAR ( 'Date'[Date] )
      VAR _RelWeekStart =
          FORMAT ( _Today + ( _RelWeek - 1 ) * 7 + 5, "mm/dd/yyyy" )
      VAR _RelWeekEnd =
          FORMAT ( _Today + ( _RelWeek - 1 ) * 7 + 11, "mm/dd/yyyy" )
      VAR _RelDateWeek = _RelWeekStart & " - " & _RelWeekEnd
      VAR _Label =
          IF ( _RelWeek = 0 || _RelWeek = -1, _RelDateDay, _RelDateWeek )
      RETURN
          _Label
      ?

      You’ll probably need to experiment and debug the code above. It’s sometimes useful to replace the return value (currently _Label) with intermediate results to check whether they are evaluating as expected.

      ——————————
      Steve James
      Director
      ——————————
      ——————————————-

    DSC Communities replied 5 years, 9 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Pivot Table: Date + Weekly Display’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!