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

Calculate how many hours a worker gained as "overtime" between 01.2022 and 12.2022

Hey,

 

I have the following problem. I have two tables:

 

Salden:

 

Personalnr.NameDateGLZ
18984Laura01.01.202265,68
18984Laura31.12.202237,75

 

and the table

 

Leavings:

 

PersonalNr.NameDays on "leave" (GLZ)
18984Laura123,5

 

What I would like to do is:

65,68 (=january value) - 123,5 = -57,42 - 37,75 (=december value) = 94,99 (this is the number that should be displayed in the end. Hopefully someone can help me.

 

this was my first try:

Spalte = IF(Salden[Stichtag].[Date]="01.01.2022",SUM(Salden[GLZ])-RELATED(Days on "leave" (GLZ)])-IF(Salden[Stichtag].[Date]="31.12.2022",Salden[GLZ]))
 
but I need this per "person" so I will need to use also the personalNr.? Because every Person has a december and january date.
 
Thank you in advance
 
 
1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Laura1996 ,

 

Here are the steps you can follow:

1. Create calculated column.

Column =
var _januarey=
SUMX(
    FILTER(ALL(Salden),'Salden'[Name]=EARLIER('Salden'[Name])&&'Salden'[Date]=DATE(2022,1,1)),[GLZ])
var _december=
SUMX( FILTER(ALL(Salden),'Salden'[Name]=EARLIER('Salden'[Name])&&'Salden'[Date]=DATE(2022,12,31)),[GLZ])
var _value=
SUMX(
    FILTER(ALL(Leavings),
  'Leavings'[Name]=EARLIER('Salden'[Name])),'Leavings'[Days on "leave" (GLZ)])
return
IF(
    'Salden'[Date]=DATE(2022,12,31),
_januarey-_value-_december,BLANK())

2. Result:

vyangliumsft_0-1703223789412.png

Additionally, in calculating the data you provided, I noticed a small discrepancy that I would like to share with you. About 65.68-123.5-37.75=-95.57.

 

Best Regards,

Liu Yang

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

View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Laura1996 ,

 

Here are the steps you can follow:

1. Create calculated column.

Column =
var _januarey=
SUMX(
    FILTER(ALL(Salden),'Salden'[Name]=EARLIER('Salden'[Name])&&'Salden'[Date]=DATE(2022,1,1)),[GLZ])
var _december=
SUMX( FILTER(ALL(Salden),'Salden'[Name]=EARLIER('Salden'[Name])&&'Salden'[Date]=DATE(2022,12,31)),[GLZ])
var _value=
SUMX(
    FILTER(ALL(Leavings),
  'Leavings'[Name]=EARLIER('Salden'[Name])),'Leavings'[Days on "leave" (GLZ)])
return
IF(
    'Salden'[Date]=DATE(2022,12,31),
_januarey-_value-_december,BLANK())

2. Result:

vyangliumsft_0-1703223789412.png

Additionally, in calculating the data you provided, I noticed a small discrepancy that I would like to share with you. About 65.68-123.5-37.75=-95.57.

 

Best Regards,

Liu Yang

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

Thank you so  much 🙂 the solution works like a charm.

About the discrepancy: I wrapped the formula into "

ABS(_januarey-_value-_december)" - now the minus is gone 😉


Greg_Deckler
Super User
Super User

@Laura1996 Not quite sure I am following but you could put PersonalNr from your first table into a table visual and have a measure like this:

Spalte Measure =
  VAR __January = SUMX( FILTER( 'Salden', [Date] = "01.01.2022", [GLZ])
  VAR __December = SUMX( FILTER( 'Salden', [Date] = "31.12.2022", [GLZ])
  VAR __Leave = SUMX( 'Leavings', [Days on "leave" (GLZ)] )
  VAR __Result = __January - __Leave - __December
RETURN
  __Result

@ 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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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