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
boby
Regular Visitor

Compare sameperiodlastyear, from date to date

Hi all,

 

eg : total amount = CALCULATE(sum(TABLE1[amount]); LASTDATE(TABLE1[Date]))  = 23

Total amount sameperiodlastyear =  CALCULATE([total amount ]; SAMEPERIODLASTYEAR(TABLE1[Date]))  = 31

 

I'd like to compare 2015 and 2016. from date to date :

 

today is  23/12/2016 : I want to compare from 1/12/2016 to 23/12/2016 with 01/12/2015 to 23/12/2015.

 

Thanks in advance for the assistance.

 

DateAmountCumulatifAmontDateAmountCumulatifAmont
01/12/20151101/12/201611
02/12/20151202/12/201612
03/12/20151303/12/201613
04/12/20151404/12/201614
05/12/20151505/12/201615
06/12/20151606/12/201616
07/12/20151707/12/201617
08/12/20151808/12/201618
09/12/20151909/12/201619
10/12/201511010/12/2016110
11/12/201511111/12/2016111
12/12/201511212/12/2016112
13/12/201511313/12/2016113
14/12/201511414/12/2016114
15/12/201511515/12/2016115
16/12/201511616/12/2016116
17/12/201511717/12/2016117
18/12/201511818/12/2016118
19/12/201511919/12/2016119
20/12/201512020/12/2016120
21/12/201512121/12/2016121
22/12/201512222/12/2016122
23/12/201512323/12/2016123
24/12/201512424/12/20161 
25/12/201512525/12/20161 
26/12/201512626/12/20161 
27/12/201512727/12/20161 
28/12/201512828/12/20161 
29/12/201512929/12/20161 
30/12/201513030/12/20161 
31/12/201513131/12/20161 
1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@boby

 

Maybe exist a short version but i'll go to a meeting and don't have time to optimize

 

MTD =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( DATESMTD ( Calendario[Date] ), Calendario[Date] <= TODAY () )
)
M2 MTD LY =
CALCULATE (
    [MTD],
    FILTER (
        DATEADD ( Calendario[Date], -1; YEAR ),
        Calendario[Date]
            <= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
    )
)



Lima - Peru

View solution in original post

6 REPLIES 6
austinsense
Impactful Individual
Impactful Individual

First, if you're going to do time intelligence you need a date table that you connect to your data table.

1. Contiguous dates (don't skip any days)

2. Every day once (no duplicate dates).

 

Second, when you write time intelligence functions, always reference the date table.

 

Third, Month-to-Date (MTD) is like this ... https://msdn.microsoft.com/en-us/library/ee634359.aspx

 

MTD Sales = CALCULATE( Table[Amount], DATESMTD(DateTable[Date]) )

 

Fourth, Month-to-Date Last Year (MTD LY) ... https://msdn.microsoft.com/en-us/library/ee634905.aspx

MTD Sales LY = CALCULATE( [MTD Sales], DATEADD(DateTable[Date], -1, YEAR) )

 

Austin is VP Operations at PowerPivotPro and a professional self-service enthusiast 🙂

I have a date table to connect with my data table. but i'm doing something wrong !!

 

M0 = CALCULATE(sum(Test[Amount]); DimDate[year] = 2015) the mesure is 31

M1 = CALCULATE(sum(Test[Amount]); DimDate[year] = 2016) the mesure is 23

MTD = CALCULATE(sum(Test[Amount]) ; DATESMTD(DimDate[Date]))  nothing why ?

M2 MTD LY = CALCULATE([MTD] ; DATEADD(DimDate[Date]; -1; YEAR)) nothing why ?

 

what i want is :

Result of current month : 23 (from 1/12/2016 to 23/2016

Result of last year : 23  : (from 1/12/2015 to 23/12/2015

 

Thank you

Vvelarde
Community Champion
Community Champion

@boby

 

Maybe exist a short version but i'll go to a meeting and don't have time to optimize

 

MTD =
CALCULATE (
    SUM ( Table1[Amount] ),
    FILTER ( DATESMTD ( Calendario[Date] ), Calendario[Date] <= TODAY () )
)
M2 MTD LY =
CALCULATE (
    [MTD],
    FILTER (
        DATEADD ( Calendario[Date], -1; YEAR ),
        Calendario[Date]
            <= DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
    )
)



Lima - Peru

@Vvelarde, there may be a shorter solution, but this worked for me first time and because of the format means I can understand what is happening in the formula. Maybe I will take a look at shortening it myself when I have a bit more experience with Power BI.

 

Thanks for the post


Awesome, works perfectly.

I need to analyse this long formula after vacation.

Thank you

and Merry Christmas and a happy New year

Hi @boby,

I very gald the formula work perfectly, please mark the corresponding reply as solution, which will help more people.

Best Regards,
Angelia

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.