• Skip to main content
  • Skip to primary sidebar
  • Skip to footer

bVisual

  • Home
  • Services
    • How Visio smartness can help your business
    • Visio visual in Power BI
    • Visio Consulting Services
    • Visio Bureau Services
    • Visio Training and Support Services
  • Products
    • Visio Shape Report Converter
    • SS Plus
    • LayerManager
    • visViewer
    • Metro Icons
    • Rules Tools for Visio
    • The Visio 2010 Sessions App
    • Multi-Language Text for Visio
    • Document Imager for Visio
    • multiSelect for Visio
    • pdSelect for Visio
  • Case Studies
    • Case studies overview
    • Using Visio in Education for GIS
    • Visualizing Construction Project Schedules
    • Visio Online Business Process Mapping
    • Nexans Visio Template
    • CNEE Projects, WorldCom
    • Chase Manhattan Bank
  • News
    • Recent news
    • News archive
  • Resources
    • Articles➡
      • ShapeSheet Functions A-Z
      • Comparing Visio for the Web and Desktop
      • Customising Visio Shapes for the Web App
      • Key differences between the Visio desktop and web apps
      • Using the Visio Data Visualizer in Excel
      • Using Visio in Teams
      • Creating Visio Tabs and Apps for Teams with SharePoint Framework (SPFx)
      • Designing Power Automate Flows with Microsoft Visio
      • Innovative uses of Visio Lists
    • Webcasts ➡
      • Visio in Organizations
      • My session and other Visio sessions at MSIgnite 2019
      • Power up your Visio diagrams
      • Vision up your Visio diagrams
      • The Visio 2010 MVP Sessions
    • Visio Web Learning Resources
    • Books➡
      • Visualize Complex Processes with Microsoft Visio
      • Mastering Data Visualization with Microsoft Visio
      • Microsoft Visio Business Process Diagramming and Validation
      • Visualizing Information with Microsoft Visio
  • Blog
    • Browse blog articles
    • Visio Power BI articles
    • Visio for Web articles
    • A history of messaging and encryption
  • About us
    • About bVisual
    • Testimonials
    • Bio of David Parker
    • Contact Us
    • Website Privacy Policy
    • Website terms and conditions
    • Ariba Network
You are here: Home / Visio / Writing a WeekNum(…) function for Visio

Published on July 22, 2019 by David Parker

Writing a WeekNum(…) function for Visio

I needed to display the week number of dates in a Visio project of mine, but there is no WeekNum(…) function built-in, so I had to write one, and allow for the date that the week numbers begin in to be varied from 1st January.  I also needed to allow for the week numbers to go backwards from the specified week number begin date.
Excel has a WeekNum(..) function, which can take an optional parameter for the day of the week to begin on, and an IsoWeekNum(..) function, and the following table shows the values change for the first 35 days of the year:
Excel Week Num Formulas

What this graphic shows is that the Excel IsoWeekNum(<date>) function returns the same value as WeekNum(<date, 11) and WeekNum(<date>,21) functions.
Excel defaults to weeks beginning on a Sunday, but Visio defaults to weeks beginning on a Monday, as follows:

DayExcel Weekday(<date>)Visio Weekday(<date>)
Sunday17
Monday21
Tuesday32
Wednesday43
Thursday54
Friday65
Saturday76

A formula can be written in the Visio ShapeSheet to return the weekday number starting on Sunday, as follows:

=MODULUS(WEEKDAY(<date>),7)+1

However, in my test Visio shape, I created a fixed list that is in the order starting with Sunday, so the index of the selected day is from 0 to 6, using the formula:

=LOOKUP(Prop.WeekBeginsOn,Prop.WeekBeginsOn.Format)

This test Visio shape has some User-defined Cells and Shape Data rows so that I can enter/select a date, configure the options, and get the week number:
VisioWeekNumFormulas
So, I can select the start day of the week for the week numbers, Week Begins On, and the date which is defines the first week, I can also configure Reset Annually to be TRUE if the numbers are always from 1 to 52, like Excel, or FALSE if the numbers are 1, 2, etc forwards from the date, and -1,-2, etc backwards from the date.
The User.WeekNumStartsOn formula is :

=Prop.BeginWeekDate-MODULUS(WEEKDAY(Prop.BeginWeekDate),7)+User.WeekBeginsOn

The guarded formula in Prop.WeekNum displays the week number accordingly:

=IF(Prop.ResetAnnually,
MODULUS(INT((Prop.Date-User.WeekNumStartsOn)/7 ed)+
 (Prop.Date>=User.WeekNumStartsOn),52)+NOT(Prop.Date>=User.WeekNumStartsOn),
INT((Prop.Date-User.WeekNumStartsOn)/7 ed)+(Prop.Date>=User.WeekNumStartsOn)
)

This could be abstracted even more by moving the code into a User-defined cell, say User.WeekNum, with the formula:

=IF(ARG("r"),
MODULUS(INT((ARG("d")-ARG("s"))/7 ed)+
 (ARG("d")>=ARG("s")),52)+NOT(ARG("d")>=ARG("s")),
INT((ARG("d")-ARG("s"))/7 ed)+(ARG("d")>=ARG("s"))
)

where “r” is the reset annually value, “d” is the target date, and “s” is the date that week numbers start.
Then the Prop.WeekNum formula can be:

=GUARD(EVALCELL(User.WeekNum,
"r",Prop.ResetAnnually,"d",Prop.Date,"s",User.WeekNumStartsOn))

So, how can this be used? Well, in this following example, I added these formulas to the Diamond milestone master in a Timeline diagram. I set the week numbers to begin on 1st July 2019, and you can see the effect of resetting the week numbers automatically or not:
Week Nums in Timelines
I used Data Graphics to display the Prop.WeekNum values above each milestone.
View Week Numbers on Timelines.vsdx
Update : Well, not for the first time, I find that my friend, and fellow Visio MVP, Chris Roth has previously solved a similar problem, but without the variable start date, so also check out Calculate work weeks for your visio shapes/
So I added my formulas to the Month, Thumbnail month, Week, Multiple week masters in the document stencil. I had to add in a more advanced technique of pushing the formulas into the Prop.StartWeekNum and Prop.EndWeekNum cells on a some of these because a Microsoft add-on updates the dates using the right mouse Configure… option, which was not refreshing the formula. I also found that I had to re-apply the Data Graphics to the shapes if I used the Configure... dialogue.
Week Nums in Calendars
I have provided the document for download below so the User.WeekNumsTriggers formula can be seen in action, eg:

=DEPENDSON(Prop.StartDate,Prop.EndDate)+
SETF(GetRef(Prop.StartWeekNum),
"=GUARD(EVALCELL(User.WeekNum,""r"",Prop.ResetAnnually,""d"",Prop.StartDate,""s"",User.WeekNumStartsOn))")+
SETF(GetRef(Prop.EndWeekNum),
"=GUARD(EVALCELL(User.WeekNum,""r"",Prop.ResetAnnually,""d"",Prop.EndDate,""s"",User.WeekNumStartsOn))")

View Week Numbers on Calendars.vsdx

Related

Filed Under: Shape Data, ShapeSheet Formulas, TimeTable, Visio, Visio 2016 Tagged With: Excel, ShapeSheet Functions

About David Parker

David Parker has 25 years' experience of providing data visualization solutions to companies around the globe. He is a Microsoft MVP and Visio expert.

Reader Interactions

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

  • LinkedIn
  • Twitter

Recent Posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

Categories

Tags

Accessibility Add-Ins Connectors Containers Data Export Data Graphics Data Import Data Visualizer Educational Excel GraphDatabase Hyperlinks Icon Sets JavaScript LayerManager Layers Legend Link Data to Shapes Lists MSIgnite MVP Office365 Org Chart PowerApps PowerBI PowerQuery Processes Setup and Deployment Shape Data Shape Design ShapeSheet ShapeSheet Functions SharePoint 2013 SQL Teams Validation VBA Video Visio Visio 2007 Visio for the Web Visio Online Visio Services Visio Viewer Webinar

Footer

bVisual Profile

The UK-based independent Visio consultancy with a worldwide reach. We have over 25 years experience of providing data visualization solutions to companies around the globe.

Learn more about bVisual

  • Amazon
  • E-mail
  • Facebook
  • LinkedIn
  • Twitter
  • YouTube

Search this website

Recent posts

  • Co-authoring and Commenting with Visio Documents
  • Fixing dimensions of 2D shapes
  • Merging Linked Data from Similar Tables
  • Smart Radio Buttons and Check Boxes in Visio
  • Using Button Face Ids in Visio

Copyright © 2025 · Executive Pro on Genesis Framework · WordPress · Log in