Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
The source is Direct Query SQL Server
I am trying to determine the previous day (month, year) count, but only to the current point in time.
End goal: IsToday = 1, IsPreviousDay = 1, IsCurrentMonth = 1, IsLastMonth = 1
...but only up to this point in time (NOW()).
Example
Previous Day Total is 75
Previous Day Total up to NOW() is33
pDtH stands for "Previous Day to Hour
The code snippet below works, but it returns the entire hour. I need it to stop at the current minute...I hope that makes sense.
pDtH =
IF.EAGER (
YEAR ( CFS[Date CFS Received] ) = YEAR ( TODAY () )
&& MONTH ( CFS[Date CFS Received] ) = MONTH ( TODAY () )
&& DAY ( CFS[Date CFS Received] )
<= DAY ( TODAY () ) - 1
&& HOUR ( CFS[Time CFS Received] ) <= HOUR ( NOW () ),
1,
0
)
The code below is where I am needing assistance.
pDtH =
IF.EAGER (
YEAR ( CFS[Date CFS Received] ) = YEAR ( TODAY () )
&& MONTH ( CFS[Date CFS Received] ) = MONTH ( TODAY () )
&& DAY ( CFS[Date CFS Received] )
<= DAY ( TODAY () ) - 1
&& HOUR ( CFS[Time CFS Received] ) <= HOUR ( NOW () )
1,
0
)
Maybe I have been looking at this too long to see the obvious. 🙂
Solved! Go to Solution.
For what it might be worth, here is a working version done in Microsft SQL:
FROM [database].[dbo].[table] t
WHERE YEAR([t].[DateTimeReceived]) = YEAR(GETDATE())
AND DATEPART(MONTH, [t].[DateTimeReceived]) = DATEPART(MONTH, GETDATE()) --Gets the Current Month
AND DATEPART(DAY, [t].[DateTimeReceived]) = DATEPART(DAY, GETDATE()) -1 --Gets the Previous Day
AND CONVERT(VARCHAR, [t].[DateTimeReceived], 114) <= CONVERT(VARCHAR, GETDATE(), 114) --Gets the Current Time Stamp
@JPBTech Can you just do this?
pDtH = IF(CFS[Date CFS Received] <= NOW() - 1,1,0)
For what it might be worth, here is a working version done in Microsft SQL:
FROM [database].[dbo].[table] t
WHERE YEAR([t].[DateTimeReceived]) = YEAR(GETDATE())
AND DATEPART(MONTH, [t].[DateTimeReceived]) = DATEPART(MONTH, GETDATE()) --Gets the Current Month
AND DATEPART(DAY, [t].[DateTimeReceived]) = DATEPART(DAY, GETDATE()) -1 --Gets the Previous Day
AND CONVERT(VARCHAR, [t].[DateTimeReceived], 114) <= CONVERT(VARCHAR, GETDATE(), 114) --Gets the Current Time Stamp
HI, @Greg_Deckler, thank you for taking the time to reply.
Implementing that piece of code returns the value of 1 for all dates "below" now.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
102 | |
84 | |
79 | |
68 |
User | Count |
---|---|
120 | |
110 | |
94 | |
81 | |
77 |