<?xml version="1.0" encoding="utf-16"?>
<Function xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.caseware-idea.com/">
    <Author>eleme</Author>
    <DateModified>2025-05-04</DateModified>
    <FunctionName>GreaterThanXBusDays</FunctionName>
    <Help>This custom function will return 1 if a date is greater than x business days from the end of the prior month else it will return 0.

Parameters: Date field - Holds the date to be checked
                    Days - Holds the number of business days from start of month - this will return 0 if over 20 days.
                    Current_Month - Date that contains the year and month that will be tested against.  The days will be ignored.

Return: 1 if true and 0 if false</Help>
    <OutputType>Numeric</OutputType>
    <ScriptType>VbScript</ScriptType>
    <Category>DateTime</Category>
    <FunctionBody>Option Explicit
Function GreaterThanXBusDays(DateField As Date, Days As Double, Current_Month As Date) As Double
	Dim iCurrentMonth As Integer
	Dim iCurrentYear As Integer
	Dim i As Integer
	Dim testDate As Date
	Dim iDateCount As Integer
	
	'if the number of business days is larger than 20 than return 0
	If days &gt; 20 Then
		GreaterThanXBusDays = 0
		Exit Function
	End If
	
	'get the current month
	iCurrentMonth = Month(Current_Month)
	iCurrentYear = Year(Current_Month)

	'if date is different year or month return 0
	If iCurrentMonth = Month(DateField) and iCurrentYear = Year(DateField) Then
		'calculate the last business date for the number of days (excludes Saturdasy and Sundays)
		For i = 1 To 31
			testDate = DateSerial(iCurrentYear, iCurrentMonth, i)
			If Weekday(testDate) &lt;&gt; 1 And Weekday(testDate) &lt;&gt; 7 Then
				iDateCount = iDateCount + 1
				If iDateCount = Days Then
					Exit For
				End If
			End If
		Next i 
	Else
		GreaterThanXBusDays = 0
		Exit Function
	End If
	If DateField &lt;= testDate Then
		GreaterThanXBusDays = 1
	Else
		GreaterThanXBusDays = 0
	End If
End Function
</FunctionBody>
    <Parameters>
        <Parameter>
            <Type>Date</Type>
            <Name>DateField</Name>
            <Help>Date field that is being tested</Help>
        </Parameter>
        <Parameter>
            <Type>Numeric</Type>
            <Name>Days</Name>
            <Help>Number of business days from start of month</Help>
        </Parameter>
        <Parameter>
            <Type>Date</Type>
            <Name>Current_Month</Name>
            <Help>A date which will be used for the current month, the day will be ignored</Help>
        </Parameter>
    </Parameters>
</Function>