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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Laura1996
Helper I
Helper I

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Community Champion
Community Champion

@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


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.