Calculating Same Day Last Week only works partially in Power BI

muhammadahmad21

New Member
Joined
Mar 13, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have this DAX that is supposed to return appointments for the same day last week by each brand for each date. It is working absolutely fine and giving me the desired results as I intended. The only issue is that for some brands, where there are 0 appointments for the current date, it shows 0 for the same day last week as well when there are actually appointments on the same day last week. The grand total number shows all appointments that matches with the same day last week but when I look at it by brand, it's missing some appointments.

Appointments SDLW =
VAR SameDayLastWeek = DATEADD('appointments_report'[START_DATE], -7, DAY)
VAR TotalAppointments = CALCULATE(COUNTROWS('appointments_report'),
'appointments_report'[APPOINTMENT_STATUS] IN {"Done", "Scheduled", "Working"},
SameDayLastWeek
)
RETURN
IF( ISBLANK(TotalAppointments), 0, TotalAppointments )


For more context, I have attached a screenshot of an example as well. See the highlighted 03/03/24, Sunday and 03/10/24, Sunday. The grand total number of Previous for 03/10/24, Sunday matches with the grand total number of Current for 03/03/24, Sunday but it only shows 8 for just 1 brand for the Previous 03/10/24, Sunday when clearly there are more in Current 03/03/24, Sunday for other brands. I noticed that whereever there are 0s in Current, it shows 0 as well in the Previous.

I hope I am able to clearly explain the issue. Could anyone please help me here as I have been scratching my head over this since last 3 hours.

1710362985526.png
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You should never write time intelligence functions over a transactional table. Create a calendar table, join it in the model, then use that, not the date column in your data table. There are many reasons why, but in this case, your IN statement is applying some filter to the data table. This can negatively impact the time intelligence calc. Having a calendar table abstracts the concept of contiguous days from other filters.

Here’s an article I wrote on the topic
 
Last edited:
Upvote 0
Solution
You should never write time intelligence functions over a transactional table. Create a calendar table, join it in the model, then use that, not the date column in your data table. There are many reasons why, but in this case, your IN statement is applying some filter to the data table. This can negatively impact the time intelligence calc. Having a calendar table abstract the concept of contiguous days from other filters.

Here’s an article I wrote on the topic
Thanks man, this worked! This was such a rookie mistake lol I even made a calendar table but I wasn't using it thinking I don't need it. Turns out I did. Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,771
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top