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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
OscarHernandez
Frequent Visitor

DATEADD function with CALCULATE not working as expected

Hi all,

 

I am seeing that my LastMonth metric is not returning the expected results depending on what Dates I'm filtering.

My data model has a Calendar table with dates that range from 01/01/2022 to 05/03/2024 (DD/MM/YYYY) which is related to a Fact table. Then I created the following measures:

Measure= DISTINCTCOUNT(MyTable[MyColumn])
Measure_LM = CALCULATE([Measure],DATEADD('Calendar'[Date],-1,MONTH))
Then I have a slicer that lest me select which Calendar'[Date] I want to filter.
Measure_LM works perfectly when my slicer is selecting anything but the maximum Date from my Calendar table. However, when my slicer is set to 01/03/2024-05/03/2024, the value I get from Measure_LM is not the DISTINCTCOUNT from 01/02/2024-05/02/2024 but I'm getting the values of the whole month 01/02/2024-29/02/2024. 
Why does DATEADD take "full month" when my slicer is set to the maximum available 'Calendar'[Date]? 
 
Thanks in advance!
2 REPLIES 2
amitchandak
Super User
Super User

@OscarHernandez , Make sure the slicer is on the column from the date table . I tried same on Table and card visual. I getting value for those days

 

amitchandak_0-1709698944695.png

 

 

 

Hi @amitchandak,

Thanks for your response. I checked my slicer and it is already using the date column from the calendar table.

Looking at you screenshot, I see that your slicer is not set to the maximun posible date which is the problem I'm facing right now. I am attaching 2 screenshot so you can better see what my problem is. Plese note that, in this example, the maximum date in the calendar table is 03/03/2024 (DD/MM/YYYY)

In the first screenshot, metrics for LastMonth (_LM) and LastYear (_LY) are working as expected, aggregating data from 01/02/2024-02/02/2024 and 01/03/2023-02/03/2023 respectively. 

OscarHernandez_0-1709717832780.png

In the second screenshot, you can see that the result shown in card visual or total row in table visual is not working properly. It is aggregating data from 01/02/2024-29/02/2024 in _LM metric and 01/03/2023-31/03/2023 in _LY metric. 

OscarHernandez_1-1709718178469.png

Do you know why is it working like that? It seems like it is treating the maximum available date as "end of month" so it converts into last day of the month in LastMonth/LastYear metrics.

 

Thanks for your time.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.