cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
webportal Member
Member

How to express Today "one month ago"

Hello,

 

I want to create a card with last month's sales.

For that, I need a measure that is capable of expressing today "one month ago"

 

For example, this month's sales is:

 

This month sales = VAR ThisMonth = MONTH(TODAY()) RETURN CALCULATE('orders'[SalesAmount];'calendar'[month_number]=ThisMonth; 'calendar'[year]=2017)

All time intelligence functions seem to be good to handle columns of date but not scalar values like this case is. 

Also, because I'm using a card, there's no "filter context", therefore, I need a volatile function like TODAY.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
v-yulgu-msft Super Contributor
Super Contributor

Re: How to express Today "one month ago"

Hi @webportal,

 

To consider the month January, how about try this:

Last month sales =
VAR LMonth =
    IF ( MONTH ( TODAY () ) = 1, 12, MONTH ( TODAY () ) - 1 )
VAR YearNum =
    IF ( MONTH ( TODAY () ) = 1, YEAR ( TODAY () ) - 1, YEAR ( TODAY () ) )
RETURN
    CALCULATE (
        SUM ( 'Previous month sales'[Sales] ),
        MONTH ( 'calendar'[Date] ) = LMonth,
        YEAR ( 'calendar'[Date] ) = YearNum
    )

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

6 REPLIES 6
Highlighted
webportal Member
Member

Re: How to express Today "one month ago"

I found out this works:

 

Last month sales = VAR LastMonth = MONTH(TODAY()-DAY(TODAY()) RETURN CALCULATE('orders'[SalesAmount];'calendar'[month_number]=LastMonth; 'calendar'[year]=2017)

Although probably it's not the most correct syntax.. 

Super User
Super User

Re: How to express Today "one month ago"

Hi,

 

Even if you do not have a Date column in your base data but simple Month and year columns, we can always create a date column from these 2 columns.  This will then allow us to use the Date/Time Intelligence functions.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yulgu-msft Super Contributor
Super Contributor

Re: How to express Today "one month ago"

Hi @webportal,

 

Based on my test, measure similar to below could return last month sales dynamically.

Last month sales =
VAR LMonth =
    MONTH ( TODAY () ) - 1
RETURN
    CALCULATE (
        SUM ( 'Previous month sales'[Sales] ),
        MONTH ( 'calendar'[Date] ) = LMonth,
        YEAR ( 'calendar'[Date] ) = 2017
    )

So, what is your concern? As you mentioned, almost time intelligence functions supports date column rather than scalar values like Today(). This is by design, but you could use above workaround.

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
webportal Member
Member

Re: How to express Today "one month ago"

Hello,

Thanks, will it also work if today is in January?

What will LMonth be then?

v-yulgu-msft Super Contributor
Super Contributor

Re: How to express Today "one month ago"

Hi @webportal,

 

To consider the month January, how about try this:

Last month sales =
VAR LMonth =
    IF ( MONTH ( TODAY () ) = 1, 12, MONTH ( TODAY () ) - 1 )
VAR YearNum =
    IF ( MONTH ( TODAY () ) = 1, YEAR ( TODAY () ) - 1, YEAR ( TODAY () ) )
RETURN
    CALCULATE (
        SUM ( 'Previous month sales'[Sales] ),
        MONTH ( 'calendar'[Date] ) = LMonth,
        YEAR ( 'calendar'[Date] ) = YearNum
    )

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

webportal Member
Member

Re: How to express Today "one month ago"

Hi @v-yulgu-msft

 

Thank you so much for your assistance.

 

Happy New Year!

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Users Online
Currently online: 140 members 1,955 guests
Please welcome our newest community members: