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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Calculate difference between different value in same column against its ID.

i need to calculate the difference between different months value budgets, and the result should be the difference of two month 
against the same ID. like, e.g., ID PE-262. Now i need to find the difference between March 23 - April 23= Variance in Apr.23 . As its 
Mar.23 -Apr.23 = Varaince should appear in april.23
Apr.23 -May.23 = Varaince should appear in May.23
May.23 -June.23 = Varaince should appear in June.23
As i need variance in latest month,  and the first month should appear 0, so used this code below  , which is showing results, except when the year Change from Dec.23 to Jan.24 = varaince in Jan.24 , is showing the budget itself which is not right. need modfication for this step in this code , as other all results are accuartae , except then the year change from 2023 to 2024 only that specfic month is not ok. https://alfanargroup-my.sharepoint.com/:u:/g/personal/bilal_nawaz_alfanar_com/Ea7lulNnLsZNufAf3JH5QH... 
Screenshot 2024-06-30 143353.png

 

Differnce_month =
var _nextvalue=
SUMX(
    FILTER(ALL('Table'),
    'Table'[ID]=EARLIER('Table'[ID])&&YEAR('Table'[Version])=YEAR(EARLIER('Table'[Version]))&&
    MONTH('Table'[Version])=MONTH(EARLIER('Table'[Version]))-1
    ),[Budget])
var _diff=
[Budget] - _nextvalue
var _minmonth=
MINX(ALL('Table'),[Version])
return
IF(
    'Table'[Version]=_minmonth ,0,_diff)

 



DescriptionIDVersionBudget
Reinforcement of Thuwal Town  KAUST 2PE-2621-Mar-235.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Mar-232.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Mar-233.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Apr-2315.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Apr-2320.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Apr-2314.00
Salarie.Project Office TeamPE-262-01-001-011-Apr-2317.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-May-2412.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-May-2413.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-May-249.00
Salarie.Project Office TeamPE-2621-Jun-248.00
Salaries Site Office TeamPE-262-011-Jun-244.00
Salarie.Site Support TeamPE-262-01-0011-Jun-243.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Jul-235.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Jul-232.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Jul-233.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Aug-2315.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Aug-2320.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Aug-2314.00
Salarie.Project Office TeamPE-262-01-001-011-Aug-2317.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Sep-2412.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Sep-2413.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Sep-249.00
Salarie.Project Office TeamPE-2621-Oct-248.00
Salaries Site Office TeamPE-262-011-Oct-244.00
Salarie.Site Support TeamPE-262-01-0011-Oct-243.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Nov-235.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Nov-232.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Nov-233.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Dec-2315.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Dec-2320.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Dec-2314.00
Salarie.Project Office TeamPE-262-01-001-011-Dec-2317.00
Reinforcement of Thuwal Town  KAUST 2PE-2621-Jan-2412.00
SITE MANAGEMENT\OVERHEAD COSTPE-262-011-Jan-2413.00
SM1|SITE MANAGEMENT EXP - ADMINISTRATIPE-262-01-0011-Jan-249.00
Salarie.Project Office TeamPE-2621-Feb-248.00
Salaries Site Office TeamPE-262-011-Feb-244.00
Salarie.Site Support TeamPE-262-01-0011-Feb-243.00

 

1 ACCEPTED SOLUTION

@Anonymous 

Differnce_month = 
Var __Project = 'Table'[ID]
Var __FilterforCurrentProject = FILTER('Table', 'Table'[ID] = __Project)
Var __FirstDateOfProject = MINX(__FilterforCurrentProject,  'Table'[Version] ) 
Var __PreviousMonth = EOMONTH('Table'[Version],-2) + 1 
Var __PrevMonthBudget = MINX(FILTER(__FilterforCurrentProject, 'Table'[Version] = __PreviousMonth), 'Table'[Budget])
RETURN IF('Table'[Version] <> __FirstDateOfProject, __PrevMonthBudget - 'Table'[Budget] , 0)   


Need Power BI consultation, hire me on UpWork .


If the post helps please give a thumbs up



If it solves your issue, please accept it as the solution to help the other members find it more quickly.




Tharun



View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Thank you Bro,.

Anonymous
Not applicable

Dear @tharunkumarRTK 
as Per formula , it's showing in Jan.24 , value  0, which is not accurate  as it should show variance of Dec.23 - Jan.24= Variance in Jan.24 if have , and same for Future years. only zero should reflect at the starting Month of the Project, as its, Mar.23 which is showing 0, accurate .

Bilalmakki_0-1719809936725.png

 

lbendlin
Super User
Super User

Have you considered using Visual Calculations?

 

lbendlin_0-1719755348224.png

 

tharunkumarRTK
Super User
Super User

@Anonymous 

 

There two mistakes in your formula. In _minMonth variable, you are taking least date value in version column. Which is march 1st 2023. In the return statement you are checking, if current value of version is minMonth (march 1st 2023) if yes then then 0 else _diff. This is not correct. 

As per your expectation, for 2023 your first month is march, as you do not have past records. For 2024 and also for future years your first month is January. So, you need to write the formula accordingly. There are many ways to do this, this is one:

Differnce_month = 
var _nextvalue=
SUMX(
    FILTER(ALL('Table'),
    'Table'[ID]=EARLIER('Table'[ID])&&YEAR('Table'[Version])=YEAR(EARLIER('Table'[Version]))&&
    MONTH('Table'[Version])=MONTH(EARLIER('Table'[Version]))-1
    ),[Budget])
var _diff=
[Budget] - _nextvalue 
var __FirstMonth = 1
var _minmonth=
 MIN('Table'[Version]) 
return
IF(
    MONTH('Table'[Version])  = __FirstMonth || 'Table'[Version] = _minmonth  ,0,_diff)

 

I am not sure why you are doing this in a caclualted column, be aware calculated columns are not good for your semantic model.

 



Need Power BI consultation, hire me on UpWork .


If the post helps please give a thumbs up



If it solves your issue, please accept it as the solution to help the other members find it more quickly.




Tharun



Anonymous
Not applicable

@tharunkumarRTK 
Also if you see your code is not reflecting result in Sep.23 as there should be variance but its showing budget value,

Bilalmakki_1-1719810965757.png

 

@Anonymous 
In your data sample, you dont have any project budgets for 2024 august, thats the reason for september month, it is showing the actual budget value.

 

I have updated the formula and now you will see value for Jan 2024. (I assumed the formula as current month minus previous month, if not you can edit my code and use it)

Differnce_month = 
Var __Project = 'Table'[ID]
Var __FilterforCurrentProject = FILTER('Table', 'Table'[ID] = __Project)
Var __FirstDateOfProject = MINX(__FilterforCurrentProject,  'Table'[Version] ) 
Var __PreviousMonth = EOMONTH('Table'[Version],-2) + 1 
Var __PrevMonthBudget = MINX(FILTER(__FilterforCurrentProject, 'Table'[Version] = __PreviousMonth), 'Table'[Budget])
RETURN IF('Table'[Version] <> __FirstDateOfProject,   'Table'[Budget] - __PrevMonthBudget, 0)   

Screenshot 2024-07-01 at 4.01.42 PM.png

 



Need Power BI consultation, hire me on UpWork .


If the post helps please give a thumbs up



If it solves your issue, please accept it as the solution to help the other members find it more quickly.




Tharun



Anonymous
Not applicable

@tharunkumarRTK  Thank you very much, 
its showing proper result , can you change the formaula Prev MOnth - Current Month on this Code.

@Anonymous 

Differnce_month = 
Var __Project = 'Table'[ID]
Var __FilterforCurrentProject = FILTER('Table', 'Table'[ID] = __Project)
Var __FirstDateOfProject = MINX(__FilterforCurrentProject,  'Table'[Version] ) 
Var __PreviousMonth = EOMONTH('Table'[Version],-2) + 1 
Var __PrevMonthBudget = MINX(FILTER(__FilterforCurrentProject, 'Table'[Version] = __PreviousMonth), 'Table'[Budget])
RETURN IF('Table'[Version] <> __FirstDateOfProject, __PrevMonthBudget - 'Table'[Budget] , 0)   


Need Power BI consultation, hire me on UpWork .


If the post helps please give a thumbs up



If it solves your issue, please accept it as the solution to help the other members find it more quickly.




Tharun



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.