cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Calculating Number of orders for Previous day

Good morning,

 

Ultimately my goal is to calculate the number of transactions on the previous day excluding weekends and holidays but right now I can't even calculate the transactions of the previous day.

Measure 2 just shows no value. Measure 1 works correctly.

 

Can anyone help?

Thanks

 

Measure 1

AllOrders = DISTINCTCOUNT(Orders[Number])

Measure 2

PreviousDayOrders =
VAR PDate = LASTDATE('Calendar'[Date])

RETURN
CALCULATE ( [AllOrders],
FILTER ( ALL ( 'Calendar' ),
'Calendar'[Date] > PDate - 1 &&
'Calendar'[Date] >= PDate ) )

 

The Orders table is very simple

 

Order                                                                                                          Created

12020-07-30 08:21:07
22020-07-29 08:15:07
32020-07-29 08:12:07
42020-07-30 08:21:072020-07-30 08:21:07 

 

My Calendar table is simple as well. I have it marked as a date table.

Calendar = CALENDAR(MIN(Orders[Created]),MAX(Orders[Created]))
WeekDay = WEEKDAY('Calendar'[Date])
WeekDay / Weekend = IF ( WEEKDAY ( 'Calendar'[Date]) IN { 1, 7 }, "Weekend" , "Weekday" )


Number is datatype Whole number and it has no repeating values.
Created is datatype Date/Time and it has repeating values.

 

7 REPLIES 7
Super User IV
Super User IV

@Matt_R , This blog can help

Traveling Across Workdays
https://community.powerbi.com/t5/Community-Blog/Travelling-Across-Workdays-Decoding-Date-and-Calenda...



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

@amitchandak   Thanks I will give that approach a try.

 

Currently I'm following this youtube video which is where my current approach is from - https://www.youtube.com/watch?v=B0pC1B4w5U0

 

@Matt_R , you formula would be very similar to last week

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

You have to use that working day rank.

You might have to choose non continuous Rank , one with null on weekend



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helper I
Helper I

I found an error in my code, Measure 2 is now 

 

PreviousDayOrders =
VAR PDate = LASTDATE('Calendar'[Date])

RETURN
CALCULATE ( [AllOrders],
    FILTER ( ALL ( 'Calendar' ),
        'Calendar'[Date] > PDate - 1 &&
        'Calendar'[Date] <= PDate ) )
 
unfortunately it made no difference though.

well I figured it out. When I switched the date datatype from date / time to just date it started calculating properly.

@Matt_R 
So have you figured out and reached your expected results? The following should also give you previous day value.

 

Measure = 
var previousday = CALCULATE(MAX([Date]),FILTER(ALL('Table'),[Date]<MAX('Table'[Date])))
Return CALCULATE(DISTINCTCOUNT('Table'[Column 2]),FILTER(ALL('Table'),[Date]=previousday))

 

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I'm getting pretty close. When I add this measure to a visualization and try to group by sales agent it gives the same number for each user.

 

I know this is by design because calculate ignores context but how do I fix it? I tried wrapping the calculate in a summarize but that didnt work. I can't find anything on this topic online.

 

Thanks.

Helpful resources

Announcements
November Update

Check it Out!

Click here to read more about the November 2020 Updates!

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform October Community Highlights

Check out the top community contributors across all of the communities

secondImage

Create an end-to-end data and analytics solution

Learn how Power BI works with the latest Azure data and analytics innovations at the digital event with Microsoft CEO Satya Nadella.

Top Solution Authors
Top Kudoed Authors