Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
GA1993
Helper II
Helper II

Difference of values between current and previous month

Is there a way to subtract the current and previous month?

 

I am trying to reuse a code given to me but I keep getting this error below... 

GA1993_0-1631227595259.png

 

The formula on excel is =IF((AW9-AW8)<=0,1,0)

 

and my data should be..

GA1993_1-1631227390637.png

 

Please your help yould be really appreciated!

1 ACCEPTED SOLUTION

@GA1993 

 

Close Sum formula with bracket ")".

try this:

Measure = 
Var _TM= Max([Start Date])
Var _LM = date(year(_TM),month(_TM)-1,day(_TM))
Var _This MonthV = Calculate(sum([Phising Website]),[Start Date]=TM)
Var _PrevMonthV = Calculate(sum([Phising Website]),[Start Date]=LM)
return
if(_This MonthV-_PrevMonthV<=0,1,0)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos ✌️!!

 

 

View solution in original post

5 REPLIES 5
VahidDM
Super User
Super User

Hi @GA1993 

 

Does that Start date just have the first day of each month?

if no, can you share a sample of your data with more details as a table here
If yes, try this:

Measure = 
Var _TM= Max([Start Date])
Var _LM = date(year(_TM),month(_TM)-1,day(_TM))
Var _This MonthV = Calculate(sum([Phising Website],[Start Date]=TM)
Var _PrevMonthV = Calculate(sum([Phising Website],[Start Date]=LM)
return
if(_This MonthV-_PrevMonthV<=0,1,0)


If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos✌️!!



 

 

Hi, it doesnt need to be the first day of each month. I

 

t's more of like the values under the Start Date talks about each month (ie 2018-07, 2018-08, 2018-09, and so on)

 

GA1993_0-1631247428924.png

 

The following is the logic behing it:

AW(10) Phishing website value (current month) - 

AW(9) Phishing website value (previous month)

 

If (value above <= 0 , 1, 0)

 

I hope this helps...

 

Also, I tried your formula but I am getting the following error.. Am I doing something wrong?

 

GA1993_1-1631247841757.png

 

@GA1993 

 

Close Sum formula with bracket ")".

try this:

Measure = 
Var _TM= Max([Start Date])
Var _LM = date(year(_TM),month(_TM)-1,day(_TM))
Var _This MonthV = Calculate(sum([Phising Website]),[Start Date]=TM)
Var _PrevMonthV = Calculate(sum([Phising Website]),[Start Date]=LM)
return
if(_This MonthV-_PrevMonthV<=0,1,0)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos ✌️!!

 

 

Thank you! It worked for this. However, when I reused the code for the other fields because it has the same formula, the error below kept popping up...

 

Is there any workaround for this?

 

GA1993_0-1631250396313.png

 

Hi @GA1993 

 

Please see below links:

https://www.sqlbi.com/articles/avoiding-circular-dependency-errors-in-dax/

https://www.sqlbi.com/articles/understanding-circular-dependencies/

https://community.powerbi.com/t5/Desktop/quot-A-circular-Dependency-was-detected-quot-error-while/td...

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos ✌️!!

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.