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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to use CALCULATE with PREVIOUSYEAR?

I have the following formula:

 

Measure = CALCULATE(COUNT(table[column]); PREVIOUSYEAR(table[dates]))

 

which dies due to duplicate values in table[dates], which is apparently not supported by PREVIOUSYEAR (is there a particular reason why it cannot handle duplicates?), so I have modified the expression as follows:

 

Measure = CALCULATE(COUNT(table[column]); PREVIOUSYEAR(DISTINCT(table[dates])))

 

which again dies due to duplicate values. How is it possible that DISTINCT returns duplicates? I based the expressions on the official quick start basics and the function definitions: 

https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-quickstart-learn-dax-basics/

https://msdn.microsoft.com/en-us/library/ee634770.aspx

https://msdn.microsoft.com/en-us/library/ee634943.aspx

 

Thank you for your help guys!

1 ACCEPTED SOLUTION

@Anonymous yes you do its best practice when using date functions

 

its easy to create one to either use the calendarauto() function in dax, or i usually go for this

 

https://www.mattmasson.com/2014/02/creating-a-date-dimension-with-a-power-query-script/

 

link your date to your date (that will remove the duplication, as date functions expect continous data)

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
vanessafvg
Super User
Super User

@Anonymous you need to use a date table, have you got one?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

I have only one table with the data and a column with dates. Do I need a separate table?

@Anonymous yes you do its best practice when using date functions

 

its easy to create one to either use the calendarauto() function in dax, or i usually go for this

 

https://www.mattmasson.com/2014/02/creating-a-date-dimension-with-a-power-query-script/

 

link your date to your date (that will remove the duplication, as date functions expect continous data)

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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