cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ale Regular Visitor
Regular Visitor

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

Accepted Solutions
Community Support Team
Community Support Team

Re: Calculate function with filtering by date not working

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.
3 REPLIES 3
Super User
Super User

Re: Calculate function with filtering by date not working

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...


Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


Community Support Team
Community Support Team

Re: Calculate function with filtering by date not working

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.
Community Support Team
Community Support Team

Re: Calculate function with filtering by date not working

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.