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

View all the Fabric Data Days sessions on demand. View schedule

Reply
krampit1
Helper I
Helper I

Calculate with primary key/secondary key for history tracking

Hi all,

 

I´m facing some difficulties to get the right calculations in combination with history-tracking. 
Click here  to see my sample file.

 

Example:

Employee#1 (with primary key 1 and surrogate key 1001) has a ContractEndDate of 30-06-2021. He earns €10,00 per hour.
Employee#1 deserves a contract extension, so his ContractStartDate will be 01-07-2021 and ContractEndDate will be 31-12-2021. He earns with this contract €11,50 per hour.

Due to this situation I've added a new row with primary key 1 and surrogate key 1002.

Problem/desired result:
I would like to see the hours worked in the period of his first and second contract separately. This is important because of the €1,50 increase of hourly wage.

In my sample file the result of the first period should be 27 (=19 + 8 and the second period should be 32. (the values aren't realistic, because of a failure in my data transformation. The employee gets doubled when added a new row for him/her).

I appreciate all your help in advance.

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@krampit1 try this measure:

 

Hours Total = 
SUMX ( 
    CROSSJOIN ( Employees, SUMMARIZE('Fact table', 'Fact table'[EmployeeID], 'Fact table'[Datum], 'Fact table'[HoursTotal] ) ), 
    IF ( 
        'Fact table'[Datum] >= Employees[ContractStartDate]  && 
        'Fact table'[Datum] <= Employees[ContractEndDate], 
        CALCULATE ( SUM ( 'Fact table'[HoursTotal] ) ) 
        )
)

 

and here is the output

 

parry2k_0-1629836211666.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

2 REPLIES 2
parry2k
Super User
Super User

@krampit1 try this measure:

 

Hours Total = 
SUMX ( 
    CROSSJOIN ( Employees, SUMMARIZE('Fact table', 'Fact table'[EmployeeID], 'Fact table'[Datum], 'Fact table'[HoursTotal] ) ), 
    IF ( 
        'Fact table'[Datum] >= Employees[ContractStartDate]  && 
        'Fact table'[Datum] <= Employees[ContractEndDate], 
        CALCULATE ( SUM ( 'Fact table'[HoursTotal] ) ) 
        )
)

 

and here is the output

 

parry2k_0-1629836211666.png

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Greg_Deckler
Community Champion
Community Champion

@krampit1 
Take a look at these two Quick Measures as I think you want something like them.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365



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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors