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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
jbenson
Helper III
Helper III

Current month minus previous month

i am wanting to add a column to my table. i want to be able to subtract the current months forecast number minus the previous months forecast number. i have a month column also in the same table. i have tried a few different formulas and i always get an error. any help would be great! 

1 ACCEPTED SOLUTION

Hey @jbenson 

Lets try something more simple. To do that, you need to have a calendar table (you can create one using DAX if you don't have one).

Relate the calendar table with your Grain Margin table. After that, create two measures and that's it. See images bellow:

marcelsmaglhaes_2-1676551563394.png

marcelsmaglhaes_3-1676551592465.png

marcelsmaglhaes_6-1676551616196.png

marcelsmaglhaes_0-1676551445100.png

Best Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



View solution in original post

9 REPLIES 9
jbenson
Helper III
Helper III

i got it to work, thank you for your help!

Hey @jbenson ! 

Nice!!!! If this posts helps, please mark as solved to help other in our community.

Best Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



jbenson
Helper III
Helper III

Hey Marcel I appriciate the quick response, here is what i used for a formula 

 

FORECAST DIFFERENCE = VAR CurrentMonth = 'Grain Margin'[MONTH]
VAR PreviousMonth =
CALCULATE(MAX('Grain Margin'[MONTH]), 'Grain Margin'[MONTH] <CurrentMonth)
RETURN
IF(ISBLANK(PREVIOUSMONTH),
BLANK(),
'Grain Margin'[FORECAST]
-CALCULATE(MAX('Grain Margin'[FORECAST]),'Grain Margin'[MONTH]=PREVIOUSMONTH))
 
here is the error i got
The syntax for 'PreviousMonth' is incorrect. (DAX(VAR CurrentMonth = 'Grain Margin'[MONTH]VAR PreviousMonth =CALCULATE(MAX('Grain Margin'[MONTH]), 'Grain Margin'[MONTH] <CurrentMonth)RETURNIF(ISBLANK(PREVIOUSMONTH),BLANK(),'Grain Margin'[FORECAST]-CALCULATE(MAX('Grain Margin'[FORECAST]),'Grain Margin'[MONTH]=PREVIOUSMONTH)))).
 
 

Hey @jbenson 

Lets try something more simple. To do that, you need to have a calendar table (you can create one using DAX if you don't have one).

Relate the calendar table with your Grain Margin table. After that, create two measures and that's it. See images bellow:

marcelsmaglhaes_2-1676551563394.png

marcelsmaglhaes_3-1676551592465.png

marcelsmaglhaes_6-1676551616196.png

marcelsmaglhaes_0-1676551445100.png

Best Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



@marcelsmaglhaes 

 

the below is my sample data, i want to calculate the previous month number.

 

Swamy3105_0-1716016562667.png

 

please help me on this.

 

Regards.,

Swamy

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1716088496000.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur 

 

thanks for the help, but I was able to get the previous month data using calculated column and done the report.

 

Regards.,

Swamy

@marcelsmaglhaes 

 

can you please send me the sample PBI file to me. I'm struggling to get the exact result for the past one week. lavisam0518@gmail.com

 

Regards.,

Swamy

marcelsmaglhaes
Super User
Super User

Hey @jbenson 

Maybe you can try something like bellow:

Forecast Difference =
VAR CurrentMonth = 'Table'[Month] 
VAR PreviousMonth =
CALCULATE ( MAX ( 'Table'[Month] ), 'Table'[Month] < CurrentMonth )
RETURN
IF (
ISBLANK ( PreviousMonth ),
BLANK (),
'Table'[Forecast Number]
- CALCULATE ( MAX ( 'Table'[Forecast Number] ), 'Table'[Month] = PreviousMonth )
)


Best Regards,
Marcel


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!
Imagem de fundo



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Community Update

Fabric Community Update - April 2024

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