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

calculating difference

Hi,

 

I am stucked with the following question.

 

Product CodeSales Date
A1001/02/2022
B1001/02/2022
C1001/02/2022
D1001/02/2022
A1001/03/2022
A1001/03/2022
B1001/03/2022
C1001/03/2022
A1001/04/2022
B1001/04/2022

 

I would look for a equation that can calculate the difference between two period of time. In this data set every month I will update the sales record and I need a measure that can gives me somthing like below:

 

Assume today is Apr:

Product CodeTotal SalesDifference vs Last month
A4010
B3010
C200
D100

 

What I need is the measure that can complete "Difference vs Last month" at the same time it does not require filter on visualization.

 

I can do this by using two spreadsheet inside powerBI, however, I hope this can be on 1 spreadsheet so everytime I dont have to refresh two file.

 

Is there any way to do this?

 

Thank you!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, 

I am not sure what's wrong with my equation as it keep return error message.

 

MoM Revenue Growth =
VAR _Actual =
    sum('Table'[Sales])
VAR _PrevMonth =
    CALCULATE(
        CALCULATE(sum('Table'[Sales])),
        PREVIOUSMONTH ('Table'[Date])
    )
RETURN
    _Actual - _ PrevMonth
 
Do you know what I did wrong?
 
Thanks!

View solution in original post

9 REPLIES 9
tamerj1
Super User
Super User

Hi @Anonymous 
What is the difference?

PabloDeheza
Solution Sage
Solution Sage

Hey there!

Try this:

MoM Revenue Growth = 
VAR _Actual = 
    Total
VAR _PrevMonth =
    CALCULATE(
        Total,
        PREVIOUSMONTH( YourDateColumn )
    )
RETURN
    _Actual - _ PrevMonth

Let me know if that helps!

Anonymous
Not applicable

Hi, 

I am not sure what's wrong with my equation as it keep return error message.

 

MoM Revenue Growth =
VAR _Actual =
    sum('Table'[Sales])
VAR _PrevMonth =
    CALCULATE(
        CALCULATE(sum('Table'[Sales])),
        PREVIOUSMONTH ('Table'[Date])
    )
RETURN
    _Actual - _ PrevMonth
 
Do you know what I did wrong?
 
Thanks!

Can you please provide the error message you are getting? Thanks

Anonymous
Not applicable

The error message is like below:

 

The syntax for 'PrevMonth' is incorrect. (DAX(VAR _Actual = sum(''Table'[Sales])VAR _PrevMonth = CALCULATE( CALCULATE(sum('Table'[Sales])), PREVIOUSMONTH ('Table'[Date]) )RETURN _Actual - _ PrevMonth)).

@Anonymous 

You have a space before PrevMonth. Delete it

Anonymous
Not applicable

@tamerj1 

Hi, the equation is working now but it only gives the sum of latest month data, I believe shuld be the PREVIOUSMONTH setting not working probaly, any advice on this? 

 

Or can this criteria set as calculate the sum of the value except a sepecific date? Will that be easier? 

 

Thanks!

Anonymous
Not applicable

Hi, I have fixed the issue and the equation is now working.

 

Thank you very much!

NyeinChan
Regular Visitor

You can use either time intelligence build in function or just create common dimension column (i.e. month for you) and create a measure calculating sale difference based on current vs previous period.

 

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.

Top Solution Authors