Skip to main content
format table
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88
+------------------+------------------+------------------+------------------+ 
|Week of 2017-09-19|Week of 2017-09-26|Week of 2017-10-03|Week of 2017-10-10|
+------------------+------------------+------------------+------------------+
|234               |456               |789               |012               |
+------------------+------------------+------------------+------------------+
|Week of 2017-09-19|Week of 2017-09-26|Week of 2017-10-03|Week of 2017-10-10|
|234               |456               |789               |012               |
+------------------+------------------+------------------+------------------+ 
|Week of 2017-09-19|Week of 2017-09-26|Week of 2017-10-03|Week of 2017-10-10|
+------------------+------------------+------------------+------------------+
|234               |456               |789               |012               |
+------------------+------------------+------------------+------------------+
added 98 characters in body
Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

YouI think you can doapproach this with a loop instead of using HTML in AMPScript variables. I'd recommend using a loop based on flag_weekstart. Something like this:

You can do a loop based on flag_weekstart. Something like this:

I think you can approach this with a loop instead of using HTML in AMPScript variables. I'd recommend using a loop based on flag_weekstart. Something like this:

Source Link
Adam Spriggs
  • 31.1k
  • 6
  • 44
  • 88

You can do a loop based on flag_weekstart. Something like this:

%%[

var @Total5, @Total4, @Total3, @Total2, @Total1, @flag_weekstart, @today
set @today = now(1)
set @Total5 = AttributeValue("5Total")
set @Total4 = AttributeValue("4Total")
set @Total3 = AttributeValue("3Total")
set @Total2 = AttributeValue("2Total")
set @Total1 = AttributeValue("1Total")
set @flag_weekstart = AttributeValue("flag_weekstart")

/* for testing */
set @Total5 = "123"
set @Total4 = "234"
set @Total3 = "456"
set @Total2 = "789"
set @Total1 = "012"
set @flag_weekstart = 4

]%%

<table border="1">

  %%[

  /* output headings */

  for @i = @flag_weekstart downto 1 do

    if @i == @flag_weekstart then
      output(concat("<tr>"))
    endif

    set @headingDate = formatDate(dateadd(@today,multiply(-7,subtract(@i,1)),"D"),"YYYY-MM-DD")
    
    ]%%
      <td>Week of %%=v(@headingDate)=%%</td>
    %%[

    if @i == 1 then
      output(concat("</tr>"))
    endif

  endif

  next @i

  /* output row */
  for @i = @flag_weekstart downto 1 do

    if @i == @flag_weekstart then
      output(concat("<tr>"))
    endif

    if @i == 1 then
    ]%%
      <td>%%=v(@Total1)=%%</td>
    %%[
    endif
    if @i == 2 then
    ]%%
      <td>%%=v(@Total2)=%%</td>
    %%[
    endif
    if @i == 3 then
    ]%%
      <td>%%=v(@Total3)=%%</td>
    %%[
    endif
    if @i == 4 then
    ]%%
      <td>%%=v(@Total4)=%%</td>
    %%[
    endif
    if @i == 5 then
    ]%%
      <td>%%=v(@Total5)=%%</td>
    %%[
    endif

    if @i == 1 then
      output(concat("</tr>"))
    endif

  endif

  next @i

  ]%%

</table>

Output

|Week of 2017-09-19|Week of 2017-09-26|Week of 2017-10-03|Week of 2017-10-10|
|234               |456               |789               |012               |