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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
rks408
New Member

Create YoY Measure without error A date column containing duplicate dates was specified in the call

I am a novice at PowerBI and I'm very confused with measures and dates at the moment so any guidance would help. I'm trying to create a few year over year charts/tables that are counting the number of items created by the date created. This is what I have right now:

  • A date field Created On
  • A title field Title
  • A measure ItemCount = COUNT(table[Title]) 
  • A measure ItemCount LY = CALCULATE(COUNT(table[Title]), DATEADD(table[Created On], -1, YEAR)) 

I then tried to check if my measures worked by creating a table. I put the Created On field with only the year in the date hierarchy and the measure ItemCount. That came out fine. But when I tried to add ItemCount LY I received the error "A date column containing duplicate dates was specified in the call to function 'DATEADD'"

 

I researched this error and I understand that measures need aggregated data to work and I guess the created on field that I was referencing has multiple items with the same date. But I don't understand how to proceed. How can I get unique dates? I've looked up functions that could retrieve only unique dates, or I've seen people suggest creating a date table, but this report is not using a directquery connection. So my ability to make new columns and tables is disabled which seems to be hindering me a lot. I can only create measures. Is there any way forward? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rks408 

 

Thank you very much Sahir_Maharaj for your prompt reply.

 

Based on the screenshot information you provided, I made some adjustments to this solution:

 

vnuocmsft_1-1730797896102.png

 

vnuocmsft_0-1730797861243.png

Create measures.

 

ItemCount = COUNT('Count Table'[Title])

 

ItemCount LY = 
CALCULATE(
    COUNT('Count Table'[Title]),
    FILTER(
        'Count Table',
        YEAR('Count Table'[Created On]) <= YEAR(TODAY()) - 1
    )
)

 

Here is the result.

vnuocmsft_2-1730797972507.png

 

Regards,

Nono 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

5 REPLIES 5
Anonymous
Not applicable

Hi @rks408 

 

Thank you very much Sahir_Maharaj for your prompt reply.

 

Based on the screenshot information you provided, I made some adjustments to this solution:

 

vnuocmsft_1-1730797896102.png

 

vnuocmsft_0-1730797861243.png

Create measures.

 

ItemCount = COUNT('Count Table'[Title])

 

ItemCount LY = 
CALCULATE(
    COUNT('Count Table'[Title]),
    FILTER(
        'Count Table',
        YEAR('Count Table'[Created On]) <= YEAR(TODAY()) - 1
    )
)

 

Here is the result.

vnuocmsft_2-1730797972507.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @rks408 

 

vnuocmsft_0-1730428248282.png

 

Here's some dummy data

 

vnuocmsft_1-1730428429092.png

 

Try this:

 

ItemCount LY = 
CALCULATE(
    COUNT('Count Table'[Title]),
    YEAR('Count Table'[Created On]) = YEAR(MAX('Count Table'[Created On])) - 1
)

 

Here is the result.

 

vnuocmsft_2-1730428472266.png

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Hello, thank you for your reply. This got rid of my error message but the data isn't populating in the table correctly. 

For reference:

Table.png

The year property of the date hierarchy for Created On is being used. The dummy data you provided reflects what my data looks like. When I had Created On as just the date and not the hierarchy, 208 did populate for 2018's ReportCountLY but when the data is aggregated it is not working. Thank you 

 

 

Hello @rks408, and thank you @Anonymous for this excellent approach.

 

Building on the DAX by Nono Chen, can you please try this approach:

ItemCount LY = 
CALCULATE(
    COUNT('Count Table'[Title]),
    FILTER(
        ALL('Count Table'[Created On]),
        YEAR('Count Table'[Created On]) = YEAR(MAX('Count Table'[Created On])) - 1
    )
)

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi Sahir, 

I am still having issues with the aggregated data. As you can see when I use just the date for Created On, it is calculating 208 for all of 2018 at the row level and when I use the year from the Created On date hierarchy it is blank. Is there perhaps a different way I should be formatting Created On? Once again I am limited as I cannot create a new table or columns.  

 

table.png

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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