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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
TotalAnonymous
Helper II
Helper II

Previous Year measure - Function Dateadd expects a Contiguous Selection

Dear Community,

I hope you're doing well.

I faced an issue regarding DAX calculation. Along with this post, I've attached the PBIX through this link.

The data in here is dummy but the structure is similar with what I face.

In this case, I have a sample data that have no date field. The field that related with time is Week Number. Therefore, I created another calendar called "Year Month" as a shared dimension between "Sample Data" table with "Sample Data - 2" table.

Afterward, I created measure called "Offtake" sales. However, I'm facing struggle to create Previous Year YTD because both "Sample Data" and "Sample Data - 2" don't contain date field.

On top of that, I face this error.
 

TotalAnonymous_0-1748427260938.png

 


Have you ever face this error? Thank you

https://drive.google.com/file/d/1m_bGwkZmnJARZhgdTjivY_duA7i-eTVs/view?usp=sharing

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi, 
one of ways to achieve this is to have a proper calendar table, and this contains continuous date column.

I tried to create one more calendar table in the sample pbix file, and please check the below picture and the attached pbix file.
The data model is not well optimized, but I tried not to remove anything from your model, and add one more calendar table.

 

Jihwan_Kim_0-1748488295505.png

calendar_new = 
VAR _newdate =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2021, 1, 1 ), DATE ( 2025, 12, 31 ) ),
        "@startofmonth", EOMONTH ( [Date], -1 ) + 1
    )
VAR _generate =
    GENERATE (
        _newdate,
        FILTER (
            'Sample Calendar',
            'Sample Calendar'[Start of Month] = [@startofmonth]
        )
    )
RETURN
    _generate

 

 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


View solution in original post

Hi @TotalAnonymous,
Thank you for your thoughtful follow-up and I'm glad to hear the original solution worked for you.

Yes, it’s common to work with fact tables that aren’t at daily granularity. In such cases, here are some best practices:

  • Even if your fact has only Week Number or Start of Month, link it to a proper date table to enable time intelligence functions like DATEADD and TOTALYTD.
  • Map fact data to the calendar using Start of Month, Start of Week, or a Year-Month key.
  • Use inactive relationships and USERELATIONSHIP() when needed to keep your model clean.

The key is making sure your calendar table is continuous and your joins to it are clean and consistent.


If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

View solution in original post

5 REPLIES 5
v-ssriganesh
Community Support
Community Support

Hi @TotalAnonymous,

Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to @Jihwan_Kim for sharing valuable insights.

 

Could you please confirm if your query has been resolved by the provided solution? If so, please mark it as the solution. This will help other community members solve similar problems faster.

Thank you.

Jihwan_Kim
Super User
Super User

Hi, 
one of ways to achieve this is to have a proper calendar table, and this contains continuous date column.

I tried to create one more calendar table in the sample pbix file, and please check the below picture and the attached pbix file.
The data model is not well optimized, but I tried not to remove anything from your model, and add one more calendar table.

 

Jihwan_Kim_0-1748488295505.png

calendar_new = 
VAR _newdate =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 2021, 1, 1 ), DATE ( 2025, 12, 31 ) ),
        "@startofmonth", EOMONTH ( [Date], -1 ) + 1
    )
VAR _generate =
    GENERATE (
        _newdate,
        FILTER (
            'Sample Calendar',
            'Sample Calendar'[Start of Month] = [@startofmonth]
        )
    )
RETURN
    _generate

 

 


 

    Microsoft MVP
 

 

   


      If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


   


     
        LinkedInVisit my LinkedIn page
     

   


   


     
        Outlook BookingSchedule a short Teams meeting to discuss your question

     

   


 


Hi Jihwan, thanks for sharing. Sorry just replied your message. Please let me try your solution and come back to you ASAP. Thank you

Hi @Jihwan_Kim , I've checked the solution and it works! Thanks. I will mark it as a solution. But, I have one question. You said that the data model is not optimized. I think the data model is not optimized because the case where the first source is in Weekly granular and doesn't have date field and the second source is in monthly granular and contains only start of the month (in Date). 

Have you ever faced the case when your fact data is not in Date granular? If so, how did you tackle it and optimized your data model?

Thank you

Hi @TotalAnonymous,
Thank you for your thoughtful follow-up and I'm glad to hear the original solution worked for you.

Yes, it’s common to work with fact tables that aren’t at daily granularity. In such cases, here are some best practices:

  • Even if your fact has only Week Number or Start of Month, link it to a proper date table to enable time intelligence functions like DATEADD and TOTALYTD.
  • Map fact data to the calendar using Start of Month, Start of Week, or a Year-Month key.
  • Use inactive relationships and USERELATIONSHIP() when needed to keep your model clean.

The key is making sure your calendar table is continuous and your joins to it are clean and consistent.


If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

Helpful resources

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