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
Anonymous
Not applicable

Using a date filter in CALCULATE

Hi all,
 
I am trying to use a measure to create a baseline calculation. Ideally it would automatically use the last full year of data (2018 for now) but I would be happy with it just being hard-set on 2018. The year right now is in a date heirarchy along with the month and day so I am a little unclear if it is possible to access this in a filter without copying the column in query editor and the separating it using commas.
 
Here's the formula I have now which is not returning anything.
2018 Baseline (QTY) = CALCULATE(AVERAGE('WEEKLY_VENDOR_PURCHASE'[QTY_RECEIVED]),DATESYTD('WEEKLY_VENDOR_PURCHASE'[DATE_RECEIVED].[Year]))
 
Thanks!
1 ACCEPTED SOLUTION

Datesytd, totalytd can give you YTD. But you need to make sure input is a date.

 

In case you want filter year =2018. then you can use DATE[DATE].YEAR =2018 in filter.

 

Year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date]))

Year Sales = CALCULATE(SUM(Sales[Sales Amount]),'Date'[Date].year=2018))

 

Also prefer to a calendar, most date calculation work best with calendar.

 

https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@Anonymous for time intelligence calculations it is advised to have date calendar in your model and run all calculations from there. There are many posts to achieve this. For now, you can remove .year from your formula and see if it works.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Thanks,

 

I'll work on adding a date table, but for now I removed the .[YEAR] and got this error

 

Error Message:
MdxScript(Model) (9, 132) Calculation error in measure 'WEEKLY Tbl_MV_TM_VENDOR_PURCHASE'[2018 Baseline (QTY)]: A date column containing duplicate dates was specified in the call to function 'DATESYTD'. This is not supported.

 

Is there another date/year function that would work better than DATESYTD?

 

Datesytd, totalytd can give you YTD. But you need to make sure input is a date.

 

In case you want filter year =2018. then you can use DATE[DATE].YEAR =2018 in filter.

 

Year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date]))

Year Sales = CALCULATE(SUM(Sales[Sales Amount]),'Date'[Date].year=2018))

 

Also prefer to a calendar, most date calculation work best with calendar.

 

https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

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.