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
mwc
Frequent Visitor

Week over Week Difference

 

Hello - I'm trying to identify materials that had the greatest change in inventory dollars from today compared to the same day last week.  I've tried 20 different variations of DAX formulas, and I don't think I understand them well enough to get my desired result.  I think I'm not using the filter properly???

 

Table is called 'Inventory History Table' - let's assume that the current date is 8/8/2019 in this example.

MaterialInventory $Date Stamp
A108/1/2019
B128/1/2019
C88/1/2019
D208/1/2019
E158/1/2019
A98/8/2019
B158/8/2019
C108/8/2019
D208/8/2019
E258/8/2019

 

Expected Result

Difference week over week
A-1
B3
C2
D0
E10

 

Week over Week Difference =
(CALCULATE(SUM('Inventory History Table'[Inventory $]),LASTDATE('Inventory History Table'[Date Stamp]))) -
(CALCULATE(SUM('Inventory History Table'[Inventory $]),DATEADD('Inventory History Table'[Date Stamp],-7,DAY)))

 

The error I get with this particular formula is:

'MdxScript(Model) (19,59) Calculation error in measure 'Inventory History Table'[Week over Week Difference]: Function 'DATEADD' expects a contiguous selection when the date column is not unique, has gaps or it contains time portion.

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @mwc ,

I reproduced your question and it didn’t appear any error. You could try it again.

And usually, the reason your error appears is that if it is a measure which is using any date function which expects contiguous date range, bi-directional filter ends up removing some dates and thus it’s no longer a contiguous date range which could be crashing the measure.

So, you can create a new Date Table and manage relationships with your fact tables to solve it.

1. Create a Date Table:

Date Table = CALENDARAUTO()

 2. Manage relationships:

Week over Week Difference 2.PNG

3. Create a measure:

Week over Week Difference 2 = 
(
    CALCULATE (
        SUM ( 'Inventory History Table'[Inventory $] ),
        LASTDATE ( 'Date Table'[Date])
    )
)
    - (
        CALCULATE (
            SUM ( 'Inventory History Table'[Inventory $] ),
            DATEADD ( 'Date Table'[Date], -7, DAY )
        )
)

Week over Week Difference.PNG

Best Regards,

Icey

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @mwc ,

I reproduced your question and it didn’t appear any error. You could try it again.

And usually, the reason your error appears is that if it is a measure which is using any date function which expects contiguous date range, bi-directional filter ends up removing some dates and thus it’s no longer a contiguous date range which could be crashing the measure.

So, you can create a new Date Table and manage relationships with your fact tables to solve it.

1. Create a Date Table:

Date Table = CALENDARAUTO()

 2. Manage relationships:

Week over Week Difference 2.PNG

3. Create a measure:

Week over Week Difference 2 = 
(
    CALCULATE (
        SUM ( 'Inventory History Table'[Inventory $] ),
        LASTDATE ( 'Date Table'[Date])
    )
)
    - (
        CALCULATE (
            SUM ( 'Inventory History Table'[Inventory $] ),
            DATEADD ( 'Date Table'[Date], -7, DAY )
        )
)

Week over Week Difference.PNG

Best Regards,

Icey

 

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

mwc
Frequent Visitor

Thanks, I think it was the contiguous date issue.  The date table helped.

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.