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

Measure using DIM date table error

Hi,

 

I am trying to move a Measure from a local date to a DIM Date as I need to compare two different tables.

DateDeletionsDeletions prior to 31 days agoNumber of deletions in past 31 days
25/06/2020 00:0016 16
26/06/2020 00:0017 33
27/06/2020 00:0014 47
28/06/2020 00:0028 75
29/06/2020 00:0025 100
30/06/2020 00:0054 154
01/07/2020 00:0020 174
02/07/2020 00:0017 191
03/07/2020 00:008 199
04/07/2020 00:0010 209
05/07/2020 00:006 215
06/07/2020 00:003 218
07/07/2020 00:0011 229
08/07/2020 00:0017 246
09/07/2020 00:0010 256
10/07/2020 00:0010 266
11/07/2020 00:006 272
12/07/2020 00:0010 282
13/07/2020 00:0015 297
14/07/2020 00:006 303
15/07/2020 00:0011 314
16/07/2020 00:0011 325
17/07/2020 00:0012 337
18/07/2020 00:009 346
19/07/2020 00:009 355
20/07/2020 00:0012 367
21/07/2020 00:009 376
22/07/2020 00:005 381
23/07/2020 00:0011 392
24/07/2020 00:0012 404
25/07/2020 00:009 413
26/07/2020 00:00516418
27/07/2020 00:00433406
28/07/2020 00:00647395
29/07/2020 00:00975390
30/07/2020 00:008100370
31/07/2020 00:0017154362
01/08/2020 00:0022174330
02/08/2020 00:006191316
03/08/2020 00:0016199315
04/08/2020 00:009209316
05/08/2020 00:0013215319
06/08/2020 00:003218316
07/08/2020 00:007229320
08/08/2020 00:0010246319



This is the outcome of the table I would like and it works fine with the local measure but when I switch it to an dim date table as the calendar it goes wrong;

 

Griffy_0-1597185869199.png

 

 

From this

 

Number of deletions in past 31 days = CALCULATE (     

   SUM('Deletions' [Deletions]),     

   DATESBETWEEN('Deletions'[Date],

   MAX('Deletions' [Date]) - 31,

   Max('Deletions' [Date])))

 

 

To this

 

 

Number of deletions in past 31 days DIMDATE = CALCULATE (     

   SUM('iOS & Android - Deletions'[Deletions]),     

   DATESBETWEEN(DimDate[Date],

   MAX('Deletions' [Date]) - 31,

   Max('Deletions' [Date])))

 


I have switched the "Deletions prior to 31 days ago" messure from a local date to use the date dim table and this works just not with this one.

 

Deletions prior to 31 days ago _ DIMDATE = 
CALCULATE(SUM('Deletions'[Deletions]),
DATESBETWEEN(DimDate[Date],
BLANK(),
MAX('Deletions'[Date]) - 31))


DimDate is created with the below 

 

DimDate = CALENDAR(date(2014,01,01),date(2020,12,31))


Any idea why it might be going wrong?

 

Thanks

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

I build a new Deletions prior to 31 days ago _ DIMDATE Measure:

 

Number of deletions in past 31 days_DimDate = 
VAR _CURRENTDimDATE =
    MAX ( DimDate[Date] )
VAR _MINDATE =
    MINX ( ALL ( Deletions ), Deletions[Date] )
VAR _MAXDATE =
    MAXX ( ALL ( Deletions ), Deletions[Date] )
RETURN
    IF (
        OR ( _CURRENTDimDATE < _MINDATE, _CURRENTDimDATE > _MAXDATE ),
        BLANK (),
        CALCULATE (
            SUM ( 'Deletions'[Deletions] ),
            DATESBETWEEN (
                DimDate[Date],
                MAX ( 'Deletions'[Date] ) - 31,
                MAX ( 'Deletions'[Date] )
            )
        )
    )

 

Result:

1.png

You can download the pbix file from this link: Measure using DIM date table error

 

Best Regards,

Rico Zhou

 

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
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I build two tables like yours to have a test.

Deletions:

1.png

DimDate Table:

DimDate = CALENDAR(date(2014,01,01),date(2020,12,31))

Then build a relationship between two tables.

2.png

Build measures.

Deletions prior to 31 days ago _ DIMDATE = 
SUMX(FILTER(ALL(Deletions),Deletions[Date]<=MAX(DimDate[Date])),Deletions[Deletions])
Number of deletions in past 31 days_DIMDATE = CALCULATE(SUM(Deletions[Deletions]),DATEADD('DimDate'[Date],-31,DAY))

 Result:

3.png4.png

You can download the pbix file from this link: Measure using DIM date table error

 

Best Regards,

Rico Zhou

 

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 @v-rzhou-msft 

 

Thank you for looking in to this for me, I see what maybe my original DAX statment did work and it is having the same issue as yours.

 

If i look at the time before and after the dataset ends it has the "548" number in the blank date rows as shown below;

Griffy_0-1597223396151.png

Griffy_1-1597223405043.png

 

When it should look like this;

Griffy_2-1597223441273.png

Any ideas?

 

 

 

Hi @Anonymous 

I build a new Deletions prior to 31 days ago _ DIMDATE Measure:

 

Number of deletions in past 31 days_DimDate = 
VAR _CURRENTDimDATE =
    MAX ( DimDate[Date] )
VAR _MINDATE =
    MINX ( ALL ( Deletions ), Deletions[Date] )
VAR _MAXDATE =
    MAXX ( ALL ( Deletions ), Deletions[Date] )
RETURN
    IF (
        OR ( _CURRENTDimDATE < _MINDATE, _CURRENTDimDATE > _MAXDATE ),
        BLANK (),
        CALCULATE (
            SUM ( 'Deletions'[Deletions] ),
            DATESBETWEEN (
                DimDate[Date],
                MAX ( 'Deletions'[Date] ) - 31,
                MAX ( 'Deletions'[Date] )
            )
        )
    )

 

Result:

1.png

You can download the pbix file from this link: Measure using DIM date table error

 

Best Regards,

Rico Zhou

 

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

Ashish_Mathur
Super User
Super User

Hi,

Ensure that to your visual, you drag Date from the DimDate table.  Also, there should be a relationship from the Date column of the iOS & Android Deletions table to the Date column of the DimDate table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Use a variable to capture your current date value before entering the CALCUALATE() area, and reference the date by the variable.

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.