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
cosminzanfir
Frequent Visitor

Substract value from different month based on several conditions

Hello,
Please help me find a solution to the following problem.

 

I need to calculate the difference between this month value vs previous month.

The problem is that the calculation needs to take in consideration several other columns and make the substractions based on these columns as well.

Below you can find the columns I am working with (In excel file for calculation purposes).

The column from wich i am substracting is Time Y.m. 

The value from second month of the same year is substracted from the previous month of the same year , where Employee ID-S- ,Employee ID-H-  ,Stage and Job Key is the same. If anything changes , then a the value should be separated from the calculation.

In the table below I have marked each step in column Nr of calcul for each step.

Column Key Sort is the key made from Year*100+Month and Employee ID-S- that i tought that it will help.

In column Time Y.m based on stage and Employee ID-S- is the calculation value made in excel by hand.

 

Spoiler
timeposition.jpg

The way the data should be displayed to the user is shown in the screen below.

timeposition user display.jpg

 

Could you please advice?

Thank you

 

5 REPLIES 5
cosminzanfir
Frequent Visitor

Hello. 

So, the solution that actually worked was to create a summarize table containing all the unique key's.
in that table i've created for each record a MAX Date for employee, a MIN date for employee and found de difference between these 2 values.

v-juanli-msft
Community Support
Community Support

Hi @cosminzanfir 

Is this problem sloved? 
If it is sloved, could you kindly accept it as a solution to close this case and help the other members find it more quickly?
If not, please feel free to let me know.
 
Best Regards
Maggie

Still working on the final form. No working solution was provided but found something that does the trick. Will post once finished

amitchandak
Super User
Super User

@cosminzanfir , time intelligence, and date calendar can help you to solve these. Example

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,MONTH))))
last year MTD (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))
last year MTD Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))


last QTR same Month (complete) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-1,Qtr))))


MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date])))
MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date],-12,MONTH),"8/31")))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

If it is very specific to HR with start date end date, refer: https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

 

Appreciate your Kudos.

 

Greg_Deckler
Super User
Super User

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.