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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Employee
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
Employee
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
Super User
Super User

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


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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