cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LisaB Regular Visitor
Regular Visitor

Today compared to same day last year

Hi everyone,

 

I have a measure showing order value for today:

 

OrderValueToday = CALCULATE(SUM(PostedSalesInvoices[Amount]);PostedSalesInvoices[Order_Date] = TODAY())
                                  +
                                  CALCULATE(SUM(SalesOrderList[Amount]);SalesOrderList[Order_Date] = TODAY())
 
I wish to show a measure showing the order value for same day last year. For this I will only have one transaction table [PostedSalesInvoice] and I wish to filter on order date last year. I have tried with SAMEPERIODLASTYEAR and PREVIOUSYEAR (+ filter on today's date) without any success. 
 
Any suggestions?
 
Thanks!
 
Lisa
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Chiara Regular Visitor
Regular Visitor

Re: Today compared to same day last year

Hi @LisaB,

 

I suppose that PostedSalesInvoice table is connected to the calendar table by posting date. You can either change the relationship by connecting to the order date or you can create a new inactive relationship between calendar date and order date.

Then you can write a measure as below:

 

OrderLY =
CALCULATE (
    CALCULATE (
        SUM ( PostedSalesInvoices[Amount] ),
        USERELATIONSHIP ( PostedSalesInvoices[Order_Date], CalendarDate[Date] )
    )
        + SUM ( SalesOrderList[Amount] ),
    SAMEPERIODLASTYEAR ( CalendarDate[Date] ),
    CalendarDate[SameDayLY] = TRUE ()
)

I hope you can solve now!

 

Chiara

View solution in original post

8 REPLIES 8
rajendran Super Contributor
Super Contributor

Re: Today compared to same day last year

Hi @LisaB

 

Do you have Calendar table in your Model? If not, please create a calendar table and then you can try this DAX:

 

LastYear Numbers = CALCULATE(SUM(Sales_Fact.Sales),DATEADD(Dates[Date],-1,YEAR)

 

Thanks
Raj

Chiara Regular Visitor
Regular Visitor

Re: Today compared to same day last year

Hi @LisaB,

 

You can create a calculate column in Calendar Dimension:

 

SameDayLY= 
var TodayDate = TODAY()
var LastYear = YEAR(TodayDate)-1
var LastMonth = MONTH(TodayDate)
var LastDay = DAY(TodayDate)
return
'Calendar'[Date]= DATE(LastYear,LastMonth,LastDay)

Then a measure:

 

OrderValueSameDayLY = CALCULATE(SUM(PostedSalesInvoices[Amount]);CalendarDate[SameDayLY]=TRUE()) 
                                  +
                                  CALCULATE(SUM(SalesOrderList[Amount]);CalendarDate[SameDayLY]=TRUE())

Regards

Chiara

 

 

LisaB Regular Visitor
Regular Visitor

Re: Today compared to same day last year

 Hi @rajendran and @Chiara,

 

Thank you for your replies.

 

I've got a calendar table.

 

With the first formula (rejendran) I get the value for the whole month last year. How can I add the filter on order date = samedayLY?

 

With the second formula I didn't get anything at all. 😕

 

Worth to mention is that I have a report level filter date on this month.

 

Thanks!

 

Lisa

Chiara Regular Visitor
Regular Visitor

Re: Today compared to same day last year

After calculate column samedayLY try this measure:

 

OrderLY= CALCULATE[OrderValue], SAMEPERIODLASTYEAR(CalendarDate[Date]), CalendarDate[samedayLY] = TRUE())

 

 

LisaB Regular Visitor
Regular Visitor

Re: Today compared to same day last year

Hi @Chiara,

 

Thanks - that formula gives me a value now. However, not the value I'm looking for.

 

In my PostedSalesInvoice table, I have two dates, posting date and order date. It might be that an invoice has been posted after the order date, i.e. order date = 2018-01-29 but posting date = 2018-01-31.

 

I want to show the values filtered on order date = same date LY. Now it gives me the value of posting date = same date LY.

 

Hope this makes sense.

 

Lisa

Chiara Regular Visitor
Regular Visitor

Re: Today compared to same day last year

Hi @LisaB,

 

I suppose that PostedSalesInvoice table is connected to the calendar table by posting date. You can either change the relationship by connecting to the order date or you can create a new inactive relationship between calendar date and order date.

Then you can write a measure as below:

 

OrderLY =
CALCULATE (
    CALCULATE (
        SUM ( PostedSalesInvoices[Amount] ),
        USERELATIONSHIP ( PostedSalesInvoices[Order_Date], CalendarDate[Date] )
    )
        + SUM ( SalesOrderList[Amount] ),
    SAMEPERIODLASTYEAR ( CalendarDate[Date] ),
    CalendarDate[SameDayLY] = TRUE ()
)

I hope you can solve now!

 

Chiara

View solution in original post

Community Support Team
Community Support Team

Re: Today compared to same day last year

Hi @LisaB,

 

Have you solved your problem?

 

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please feel free to ask.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
AsilAllaham Visitor
Visitor

Re: Today compared to same day last year

Hi @Chiara,,

Thanks for your solution it helped me a lot in a similar case that needed SameDayLY calculated column but your way returned a true value for "2019-03-01" if Today date was a Leap day for example "2020-02-29" but that was a wrong behavior according to my business requirements so I handled it as follow:

SameDayLY =
var TodayDate = TODAY() // "2020-02-29"
var TodayYear = YEAR(TodayDate)
var LastYear = YEAR(TodayDate)-1
var LastMonth = MONTH(TodayDate)
var LastDay = DAY(TodayDate)
return
IF ( MOD(TodayYear,4) = 0 && LastMonth = 2 && LastDay =29 , FALSE() , 'Calendar'[Date]= DATE(LastYear,LastMonth,LastDay))

Regards;

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors