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
MarcUrdang
Post Patron
Post Patron

Time based calculations

Hello

 

Please can you help me with this .. I have tried many different things but as a new PBI user I am struggling with this:

 

I need to calculate the variance/difference for a measure from last month (in this case Sept 19) versus same time last year (in this case = Sept 18) I can do this using filters but as you will see in the file attached to this link, 

 

https://drive.google.com/open?id=1BBtjX2jgsSTA76xgsUM7sn2yFLV4fWmT

 

that I have a measure showing 50 for last month this year being Sept and the measure for the same month last year showing 30.

 

I need to show in a card the value 20 as this would be the month this year vs month last year variance. However I would need to build this into a calc as it would have to be dynamic. ie .. next month you would see Oct 19 vs Oct 18.

 

Thanks so much,

Marc

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @MarcUrdang 

I create a simple test file as below:

Create measures

today = TODAY()

last_m_thisyear =
CALCULATE (
    SUM ( Sheet10[value] ),
    FILTER (
        Sheet10,
        Sheet10[date]
            >= DATE ( YEAR ( [today] ), MONTH ( [today] ) - 1, 1 )
            && Sheet10[date] < DATE ( YEAR ( [today] ), MONTH ( [today] ), 1 )
    )
)


last year =
CALCULATE (
    SUM ( Sheet10[value] ),
    FILTER (
        Sheet10,
        Sheet10[date]
            >= DATE ( YEAR ( [today] ) - 1, MONTH ( [today] ) - 1, 1 )
            && Sheet10[date]
                < DATE ( YEAR ( [today] ) - 1, MONTH ( [today] ), 1 )
    )
)


diff = [last_m_thisyear]-[last year]

Capture20.JPG

If today is 2019/11/2

Capture21.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
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
v-juanli-msft
Community Support
Community Support

Hi @MarcUrdang 

I create a simple test file as below:

Create measures

today = TODAY()

last_m_thisyear =
CALCULATE (
    SUM ( Sheet10[value] ),
    FILTER (
        Sheet10,
        Sheet10[date]
            >= DATE ( YEAR ( [today] ), MONTH ( [today] ) - 1, 1 )
            && Sheet10[date] < DATE ( YEAR ( [today] ), MONTH ( [today] ), 1 )
    )
)


last year =
CALCULATE (
    SUM ( Sheet10[value] ),
    FILTER (
        Sheet10,
        Sheet10[date]
            >= DATE ( YEAR ( [today] ) - 1, MONTH ( [today] ) - 1, 1 )
            && Sheet10[date]
                < DATE ( YEAR ( [today] ) - 1, MONTH ( [today] ), 1 )
    )
)


diff = [last_m_thisyear]-[last year]

Capture20.JPG

If today is 2019/11/2

Capture21.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi Maggie 

 

AMAZING AMAZING AMAZING

 

It works perfectly

 

THANK SO MUCH

regards,
Marc

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.