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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Last month same day & last week same day (excluding weekend & holiday)

Hello, 

 

I have a situation where i need to show sum of product count and Amount for category for a date selected as slicer (Single select slicer). now my requirment is to also show last week same day and last month same day count and amount though we do not have data for weekend and holidays. In such case, instead of showing 0 as amount and count, last week and last month same date should refer to max date possible excluding weekend and holiday.  here is the example - if in slicer i have 20th october selected, last month same date should be 17th september  amount and count (considering 18th as holiday and 19th and 20th as weekend). same logic should be applied in case of last week same day. Here is the sample data.

 

DateCategoryProduct CountAmount
03-08-2020C111624
03-08-2020D191371
12-08-2020E181354
12-08-2020A101936
12-08-2020E141323
18-08-2020A131898
18-08-2020B141954
18-08-2020B191365
18-08-2020A161554
18-08-2020A181125
18-08-2020E171188
18-08-2020D181505
18-08-2020C181226
20-08-2020D121927
21-08-2020B181403
24-08-2020B171202
25-08-2020D101505
26-08-2020C101964
27-08-2020D141590
28-08-2020A181195
31-08-2020A121694
01-09-2020E121453
02-09-2020A121326
03-09-2020E121945
04-09-2020D141343
07-09-2020A201619
08-09-2020A101872
09-09-2020C171268
10-09-2020A191266
11-09-2020B201513
14-09-2020B161087
15-09-2020D161498
16-09-2020A111972
17-09-2020E201399
21-09-2020E161797
22-09-2020D161272
23-09-2020A131944
24-09-2020A131412
25-09-2020E161959
28-09-2020B171880
29-09-2020B131127
30-09-2020D111572
01-10-2020C161802
02-10-2020A171840
05-10-2020D121361
06-10-2020C111665
07-10-2020D131727
08-10-2020A161445
09-10-2020A101687
12-10-2020D191680
13-10-2020C101902
14-10-2020D151875
15-10-2020C121786
16-10-2020A181873
19-10-2020D101944
20-10-2020C201582
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your requirement, you can follow my steps:

  1. Create a date table:
Date = CALENDARAUTO()

 

  1. Create some calculated columns for your main table:
Last month workday =

var _lastmonth=DATEADD('Date'[Date],-1,MONTH)

var _workday=

SWITCH(WEEKDAY(_lastmonth,2),

6,DATEADD(_lastmonth,-1,DAY),

7,DATEADD('Date'[Date],-2,DAY)

,_lastmonth

)

return _workday

Last week workday = DATEADD('Date'[Date],-7,DAY)

 

Last month workday sum amount =

CALCULATE(

    SUM('Table'[Amount]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last month workday])))

 

Last month workday sum count =

CALCULATE(

    SUM('Table'[Product Count]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last month workday])))

 

Last week workday sum amount =

CALCULATE(

    SUM('Table'[Amount]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last week workday])))

 

Last week workday sum count =

CALCULATE(

    SUM('Table'[Product Count]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last week workday])))

 

And you can get what you want, like this:

v-robertq-msft_0-1603416224287.png

 

You can download my sample pbix from here

 

Best Regards,

Community Support Team _Robert Qin

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

View solution in original post

2 REPLIES 2
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your requirement, you can follow my steps:

  1. Create a date table:
Date = CALENDARAUTO()

 

  1. Create some calculated columns for your main table:
Last month workday =

var _lastmonth=DATEADD('Date'[Date],-1,MONTH)

var _workday=

SWITCH(WEEKDAY(_lastmonth,2),

6,DATEADD(_lastmonth,-1,DAY),

7,DATEADD('Date'[Date],-2,DAY)

,_lastmonth

)

return _workday

Last week workday = DATEADD('Date'[Date],-7,DAY)

 

Last month workday sum amount =

CALCULATE(

    SUM('Table'[Amount]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last month workday])))

 

Last month workday sum count =

CALCULATE(

    SUM('Table'[Product Count]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last month workday])))

 

Last week workday sum amount =

CALCULATE(

    SUM('Table'[Amount]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last week workday])))

 

Last week workday sum count =

CALCULATE(

    SUM('Table'[Product Count]),

FILTER('Table','Table'[Date]=EARLIER('Table'[Last week workday])))

 

And you can get what you want, like this:

v-robertq-msft_0-1603416224287.png

 

You can download my sample pbix from here

 

Best Regards,

Community Support Team _Robert Qin

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

amitchandak
Super User
Super User

@Anonymous , With help from date table

 

Same weekday day lasy week =Day behind Sales = CALCULATE(SUM(Table[Amount]),dateadd('Date'[Date],-7,Day))

Have these in your date table

Work Day = if(WEEKDAY([Date],2)>=6,0,1)

Work day of month = Sumx(filter(Date, [Month year] = earlier([Month Day])),[Work Day])
Work day of week = Sumx(filter(Date, [Weekyear] = earlier([Weekyear])),[Work Day])

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)

Month Rank = RANKX(all('Date'),'Date'[Month Start date],,ASC,Dense)

 

Measures (examples)

Month Work day= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank]) && 'Date'[Work day of month] <= Max('Date'[Work day of month]) ))
last Month Work day= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Month Rank]=max('Date'[Month Rank])-1 && 'Date'[Work day of month] <= Max('Date'[Work day of month]) ))
Week till work day= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank]) && 'Date'[Work day of week] <= Max('Date'[Work day of week])))
last Week till work day= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1 && 'Date'[Work day of week] <= Max('Date'[Work day of week])))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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