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

Error with PREVIOUSMONTH - duplicatedates

HI - I am trying to build a new measure which returns the calculated value for the previous month.

 

This is the initial measure I am working with which returns the correct data:

 

MeetingsPerDay = DIVIDE(COUNTROWS(MeetingsDashboard),DISTINCTCOUNT(MeetingsDashboard[localStartDate].[Day]))

 

I then tried to create a new measure to calculate the answer for the previous month as follows:

 

MeetingsPerDayLastMonth = CALCULATE(DIVIDE(COUNTROWS(MeetingsDashboard),DISTINCTCOUNT(MeetingsDashboard[localStartDate].[Day])),PREVIOUSMONTH(MeetingsDashboard[localStartDate]))

 

but it returns a DAX error:

 

Calculation error in measure 'MeetingsDashboard'[MeetingsPerDayLastMonth]: A date column containing duplicate dates was specified in the call to function 'PREVIOUSMONTH'. This is not supported.

 

any suggestions please!

 

I need this so I can build up a KPI visual comparing this month to last month etc.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Interkoubess Established Member
Established Member

Re: Error with PREVIOUSMONTH - duplicatedates

HI @banthorpe,

 

Please create a Calendar table covering your period ( for example 2 years ..) and link this table to your fact table by the date.

 

Then you can write your measure with the previousmonth function and calendar date.

 

Hope it helps otherwise give sample data and will help.

 

Ninter.

View solution in original post

7 REPLIES 7
Interkoubess Established Member
Established Member

Re: Error with PREVIOUSMONTH - duplicatedates

HI @banthorpe,

 

Please create a Calendar table covering your period ( for example 2 years ..) and link this table to your fact table by the date.

 

Then you can write your measure with the previousmonth function and calendar date.

 

Hope it helps otherwise give sample data and will help.

 

Ninter.

View solution in original post

banthorpe Regular Visitor
Regular Visitor

Re: Error with PREVIOUSMONTH - duplicatedates

What do you mean by link the table?

Microsoft v-jiascu-msft
Microsoft

Re: Error with PREVIOUSMONTH - duplicatedates

Hi @banthorpe,

 

It's the new date table. We usually create an independent date table in your scenario. Please give it a try. 

Calendar = calendar(date(2017,1,1),date(2018,12,31))
Calendar = calendarauto()

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Microsoft v-jiascu-msft
Microsoft

Re: Error with PREVIOUSMONTH - duplicatedates

Hi @banthorpe,

 

Could you please mark the proper answers as solutions?

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
roofi00 Regular Visitor
Regular Visitor

Re: Error with PREVIOUSMONTH - duplicatedates

Hey @Interkoubess , any suggestions how to work it out when we use Power BI streaming dataset and we can't created additional dataset? 

Super User IV
Super User IV

Re: Error with PREVIOUSMONTH - duplicatedates

@roofi00 ,

Not sure how that works, but can you add an index to your table in Power Query? If so, you can use that to find the previous row.

 

Let me know if you have any questions.

 

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





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

Proud to be a Super User!




roofi00 Regular Visitor
Regular Visitor

Re: Error with PREVIOUSMONTH - duplicatedates

@Nathaniel_C , I can manipulate with dataset however I want. But for different categories may be updated in different times so I will not be able to use TOP N filter (because some values will not be shown there).

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

January 2020 Community Highlights

January 2020 Community Highlights

Make sure you didn't miss any of the things that happened in the community in January!

Top Solution Authors
Top Kudoed Authors