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
Ale
Resolver II
Resolver II

Calculate function with filtering by date not working

Dear all,
 
I have a DAX where I want to show a YTD value. Since the user selects only one month in the slicer, I had to use a Calculate function to retrieve the YTD (function TOTALYTD did not work). You can check the code below.

Sales_YTD =
VAR SD = [StartDate]
VAR ED = [EndDate]
VAR Result = CALCULATE (
SUM(GMS_View[Value]); FILTER ( ALLEXCEPT (
GMS_View; GMS_View[Brand.Brand Level 01]; GMS_View[Country.Country Level 01]); GMS_View[date] >= SD && GMS_View[date] <= ED )
) RETURN Result
 
The function uses 2 measures to get the StartDate and EndDate. They simply return the dates in the format dd.MM.yyyy, where SD is normally 01.01.yyyy and ED is 01.MM.yyyy. (we work only with month, not days, that's why I assign day 01 always)
 
The issue is: if I only have data until August/2019, and the user selects November/2019, the DAX returns blank.
 
"Fun" fact is: if instead of using the Measure [EndDate], I simply use VAR ED = DATE(2019,11,01), the function returns the correct value. So, the issue seems to be that the [EndDate] does not bring the correct value. However, the measure is returning the right value (I did the test simply returning ED instead of Result in the DAX). Which leads me to conclude that the issue is between the Measure and the Calculate function.
 
Can anyone shed some light on that? Thanks in advance!
 
 
1 ACCEPTED SOLUTION
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Ale

 

I would suggest you modify the ED like below.If it is not your case,please share the .pbix file for us to test. You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Sales_YTD =
VAR SD = [StartDate]
VAR ED = SELECTEDVALUE(Table[Slicer])
VAR Result = CALCULATE (
                       SUM(GMS_View[Value]);
                       FILTER (
                              ALLEXCEPT (
                                        GMS_View;
                                        GMS_View[Brand.Brand Level 01];
                                        GMS_View[Country.Country Level 01]);
                              GMS_View[date] >= SD && GMS_View[date] <= ED
                               )
                       )
RETURN Result

Regards,

Cherie

 

Community Support Team _ Cherie Chen
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

3 REPLIES 3
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Ale

 

I would suggest you modify the ED like below.If it is not your case,please share the .pbix file for us to test. You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Sales_YTD =
VAR SD = [StartDate]
VAR ED = SELECTEDVALUE(Table[Slicer])
VAR Result = CALCULATE (
                       SUM(GMS_View[Value]);
                       FILTER (
                              ALLEXCEPT (
                                        GMS_View;
                                        GMS_View[Brand.Brand Level 01];
                                        GMS_View[Country.Country Level 01]);
                              GMS_View[date] >= SD && GMS_View[date] <= ED
                               )
                       )
RETURN Result

Regards,

Cherie

 

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

Hi @Ale 

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution if you feel that makes sense. Welcome to share your own solution. More people will benefit from here.

 

Regards,

Cherie

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

Hmm, that's odd. Sample data would help tremendously. See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.