<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to create a Date field for a Previous Date in Visual Analytics using only Report Writer Function in SAS Visual Analytics</title>
    <link>https://communities.sas.com/t5/SAS-Visual-Analytics/How-to-create-a-Date-field-for-a-Previous-Date-in-Visual/m-p/931193#M18082</link>
    <description>&lt;P&gt;Create Custom Date Items to be used for Display or Calculations. This example will create three Items. A Date for the Previous Monday and a Date for the Previous Friday. These will be used to aggregate data between those dates. The aggregation uses the two custom dates and a date column from your data that can be used for aggregation. This is a basic way of doing a one week lookback without using filters or creating parameters.&lt;/P&gt;&lt;P&gt;Using the Following you can copy paste into a new calculated item to create a static Data Element for The previous Monday's date.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;TreatAs(_Date_, ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code will create a date for the previous Friday.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;TreatAs(_Date_, ( ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ) + 4 ))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;TreatAs(_Date_, ( ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ) + 4 ))&lt;/P&gt;&lt;P&gt;Used together to create a custom calculation&lt;/P&gt;&lt;P&gt;In the following code date_str is a column from the data loaded to VA.&lt;/P&gt;&lt;P&gt;IF ( TreatAs(_Number_, TreatAs(_Number_, 'DATE_STR'n))&lt;BR /&gt;BetweenInclusive(TreatAs(_Number_, 'PrevMonday'n), TreatAs(&lt;BR /&gt;_Number_, 'PrevFriday'n)) )&lt;BR /&gt;RETURN 'CompletedAppointments'n&lt;BR /&gt;ELSE 0&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;IF ( TreatAs(_Number_, TreatAs(_Number_, 'DATE_STR'n))
BetweenInclusive(TreatAs(_Number_, 'PrevMonday'n), TreatAs(
_Number_, 'PrevFriday'n)) )
RETURN 'CompletedAppointments'n
ELSE 0&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jun 2024 23:26:05 GMT</pubDate>
    <dc:creator>gjanuary</dc:creator>
    <dc:date>2024-06-06T23:26:05Z</dc:date>
    <item>
      <title>How to create a Date field for a Previous Date in Visual Analytics using only Report Writer Function</title>
      <link>https://communities.sas.com/t5/SAS-Visual-Analytics/How-to-create-a-Date-field-for-a-Previous-Date-in-Visual/m-p/931193#M18082</link>
      <description>&lt;P&gt;Create Custom Date Items to be used for Display or Calculations. This example will create three Items. A Date for the Previous Monday and a Date for the Previous Friday. These will be used to aggregate data between those dates. The aggregation uses the two custom dates and a date column from your data that can be used for aggregation. This is a basic way of doing a one week lookback without using filters or creating parameters.&lt;/P&gt;&lt;P&gt;Using the Following you can copy paste into a new calculated item to create a static Data Element for The previous Monday's date.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;TreatAs(_Date_, ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This code will create a date for the previous Friday.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;TreatAs(_Date_, ( ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ) + 4 ))&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;TreatAs(_Date_, ( ( ( ( TreatAs(_Number_, DatePart(Now())) - DayOfWeek(DatePart(Now())) ) + 2 ) - 7 ) + 4 ))&lt;/P&gt;&lt;P&gt;Used together to create a custom calculation&lt;/P&gt;&lt;P&gt;In the following code date_str is a column from the data loaded to VA.&lt;/P&gt;&lt;P&gt;IF ( TreatAs(_Number_, TreatAs(_Number_, 'DATE_STR'n))&lt;BR /&gt;BetweenInclusive(TreatAs(_Number_, 'PrevMonday'n), TreatAs(&lt;BR /&gt;_Number_, 'PrevFriday'n)) )&lt;BR /&gt;RETURN 'CompletedAppointments'n&lt;BR /&gt;ELSE 0&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;IF ( TreatAs(_Number_, TreatAs(_Number_, 'DATE_STR'n))
BetweenInclusive(TreatAs(_Number_, 'PrevMonday'n), TreatAs(
_Number_, 'PrevFriday'n)) )
RETURN 'CompletedAppointments'n
ELSE 0&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2024 23:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Visual-Analytics/How-to-create-a-Date-field-for-a-Previous-Date-in-Visual/m-p/931193#M18082</guid>
      <dc:creator>gjanuary</dc:creator>
      <dc:date>2024-06-06T23:26:05Z</dc:date>
    </item>
  </channel>
</rss>

