The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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:
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:
OBJECTIVE:
Overall, the objectives of this measure are:
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:
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.
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.
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.