Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DB_824
Regular Visitor

Counting 'Open Quotes' with multiple conditions and incorporating weekends/holidays constraints

Hello all,

 

PROMPT:

I need to successfully configure a DAX measure for a data card that counts the amount of 'Open Quotes' that will be due within the next 24 hours, encompassing all of the below requirements:

 

  1. 'Open Quotes' are determined by several factors:
    1. The count of rows with the 'DocNum' value as the unique identifier (from the @PBI_OPEN_QUOTES_REPORT table, described below)
    2. 'PI/PC flag' has a value of 'Y' (from the @PBI_OPEN_QUOTES_REPORT table, described below)
    3. 'Within 24 Hours Flag' has a value of 'Y' (from the @PBI_OPEN_QUOTES_REPORT table, described below)

2. As well, the measure needs to account for non-working days, which in my case would be weekends and specified holidays by day of the week and date respectively. As I have come to understand it, the former can be determined using the weekday function and the latter can be determined by creating a custom data table (this is the HolidayList table, further details provided below)

 

Some examples:

    • If today's date and time is Friday, February 16, 2024 at 2:00 PM and a quote is due Monday, February 19, 2024 at 12:00 PM, then the quote should qualify as due within 24 hours.
    • One of the holidays that the office will be closed is July 4th, which in 2024 falls on a Thursday. Therefore, hypothetically, if today's date is Wednesday, July 3, 2024 and it is 3:00 PM, and a quote is due on Friday, July 5, 2024 at 10:00 AM, then Thursday July 4th should not be counted as a weekday, which would mean the quote is due within 24 hours.

 

OBJECTIVE:

Overall, the objectives of this measure are:

  • Determine 'Open Quotes' based on the factors listed in #1
  • Reflect weekends and holidays as non-working days as shown in #2 and evidenced in bulleted examples

 

 

 

My most successful DAX measure I have configured so far looks like the following:

 

 

Within 24hrs =
VAR Today = TODAY()
VAR Tomorrow = TODAY() + 1
VAR AdjustedTomorrow =
 

IF( WEEKDAY(Tomorrow, 2) > 5 || COUNTROWS(FILTER(HolidayList, HolidayList[DATE] = Tomorrow)) > 0, Tomorrow + 2, Tomorrow )

 

VAR TotalCount =

CALCULATE( DISTINCTCOUNT('@PBI_OPEN_QUOTES_REPORT'[DocNum]),

'@PBI_OPEN_QUOTES_REPORT'[PI/PC FLAG] = "Y",

'@PBI_OPEN_QUOTES_REPORT'[Within 24 Hours Flag] = "Y",

'@PBI_OPEN_QUOTES_REPORT'[DueDateTime] <= AdjustedTomorrow

)

 

RETURN IF(ISBLANK(TotalCount), "0", IF(TotalCount = 0, "0", TotalCount))

 

 

 

Some further context/details:

  • @PBI_OPEN_QUOTES_REPORT is a data table with the following columns:
    • 'DocNum', serving as the Primary Key
    • 'PI/PC Flag', serving as one of the required values to filter for (i.e., count whenever this outputs a value of 'Y')
    • 'Within 24 Hours Flag', serving as another required value to filter for (i.e., count whenever this outputs a value of 'Y')
    • 'DueDateTime', displays the date and time that the quote would be due.
  • HolidayList table (a stagnant Excel table I created with dates manually written to signify 2024 holidays) entails the following:
    • A date column where each value is the month/day/year + time of the holiday
    • If the month/day/year + time value matches the value shown in 'DueDateTime', it should not count as a weekday (1 through 5) but instead count the same as a weekend, aka a non-working day

 

 

 

PROBLEM:

For some reason, the data card value is only output correctly as it relates to requirement #1 (defining 'Open Quotes'). It is not accurately displayed for requirement #2 (defining and factoring non-working days - weekends and holidays).

 

Please advise on what I can to do optimize the measure I already have in place, or if I need to re-configure the measure from scratch.

2 REPLIES 2
DB_824
Regular Visitor

Hello,

Thank you so much for your response. I found your response tremendously helpful, however since my post a few days ago, I am trying a different approach that I believe will get me closer to my goal. As well, I am avoiding the use of time intelligence functions in the DAX measure itself since I've tried them previously and the result was inconsistent between Power BI Desktop and Web Service instances. Meaning, the Desktop instance would show me one value and the Web Service would display another. Therefore, I went the following route:

I imported the two data tables (from a SQL Database) onto Power BI. Aforementioned in my previous post, one table is called '@PBI_OPEN_QUOTES_REPORT' and the other is called HolidayList (the holiday table), however the latter now has all dates in the year 2024 as opposed to just the office holiday dates.

1) '@PBI_OPEN_QUOTES_REPORT' has the following data columns:
-DocNum
-TomorrowDate
-TodayDate
-Within 24 Hours Flag
-PI/PC Flag
-Quote Status
-CurrentTime
-DueDateTime
-Due Date
-Due Time

Definitions for each column are:
DocNum - unique identifier representing a Quote ID
CurrentTime - displays current date and time
TodayDate - display's today's date based on CurrentTime
TomorrowDate - displays tomoprrow's date using CurrentTime
Quote Status - displays status of a quote
PI/PC Flag - searches data values of the Quote Status column and, if there is a status of 'PI', then it will output a value of 'Y'
Due Date - displaus the date that a quote is due

Due Time - displays the time of day the quote is due
DueDateTime - combines the Due Date and Due Time columns together to show the due date and time a quote is due in the same cell
Within 24 Hours Flag - outputs a value of 'Y' if the DueDateTime value is within 24 hours of the CurrentTime

2) HolidayList has the following data columns:

DATE
Holiday

Day

IsWorkingDay

Time

 

Definitions for each column:

DATE - displays a date with the day of the week, month, day and year

Holiday - displays if there is a holiday thaqt day, otherwise says 'N/A'

Day - assigns each day of the week with a number 1-7 (1 is Monday, 2 is Tuesday, and follows that pattern until Sunday, which is 7)

IsWorkingDay - dictates if that day is a working day by displaying either 'Working' or 'Non-Working'. Normal working days (weekdays, where Day value is 1-5, is 'Working', while weekends where Day value is 6 or 7 and holiday days are 'Non-Working')

Time - displays a time value

 

My objective is to create a measure that will display the number of quotes (based on Quote ID's from the DocNum column on the '@PBI_OPEN_QUOTES_REPORT' table) that, by default, meet the following conditions:
-The value of the PI/PC Flag column on the '@PBI_OPEN_QUOTES_REPORT' table for that Quote ID is 'Y'
-The value on the Within 24 Hours Flag column on the '@PBI_OPEN_QUOTES_REPORT' table for that Quote ID is 'Y'.

However, the measure must also take the following scenario into account and update data accordingly in addition to meeting the above conditions, meaning:
-If the value on the TomorrowDate column on the '@PBI_OPEN_QUOTES_REPORT' table is the same value as the DATE column on the HolidayList table where the IsWorkingDay column value is 'Non-Working' (which would either be the result of a weekend Day or a Holiday Day, then the 'Within 24 Hours Flag column data value should therefore show a value of 'Y' and thus be included in this measure's output.

The closest I have gotten is configuring the following measure:

Within 24 Hours =

VAR TomorrowDateWithNotWorking = 

CALCULATETABLE(

FILTER(

'HolidayList', 

'HolidayList'[IsWorkingDay] = "Non-Working" &&

'HolidayList'[DATE] = MAX('@PBI_OPEN_QUOTES_REPORT'[TomorrowDate])
)

)

RETURN

VAR TOTALCOUNT = 

CALCULATE (

DISTINCTCOUNT('@PBI-OPEN_QUOTES_REPORT'[DocNum]),
'@PBI_OPEN_QUOTES_REPORT'[PI/PC Flag] = "Y",
'@PBI_OPEN_QUOTES_REPORT'[Within 24 Hours Flag] = "Y"
)
RETURN

IF (

MAX('@PBI_OPEN_QUOTES_REPORT'[Within 24 Hours Flag]) = "Y"

ll COUNTROWS(TomorrowDateWithNonWorking) > 0,
TotalCount,
0
)

Please advise on what relationships I'd have to establish between the two tables (so far I've tried creating a One to Many, single relationship between HolidayList[DATE] and '@PBI_OPEN_QUOTES_REPORT'[TomorrowDate]) and how I can augment the measure I have (or create a new one) encompassing all of the above.

Anonymous
Not applicable

Hi @DB_824 ,

 

According to your description, for requirement 2 is not displayed accurately may be due to a problem with the TODAY function, because today returns the time value of all dates 12:00:00 PM, for more information about the today function you can view the documentation : TODAY function (DAX) - DAX | Microsoft Learn. it is recommended that you use the now function It is recommended that you use the now function to modify your expression so that it accurately returns the current date and time. For more information on the now function, see the documentation: NOW function (DAX) - DAX | Microsoft Learn.

Since the times in your description are all whole hours, the expression can be written as

VAR _Today = DATE(YEAR(TODAY()),MONTH(TODAY()),DAY(TODAY())) + TIME(HOUR(NOW()),0,0) to be able to match the time in your holiday table.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors