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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
ravelrausch
Frequent Visitor

Calculate Hours for the following week

I have 2 date columns - one shows the start of each main week. the other one shows the start of the next week. 
i have an Hours column which shows the sum of hours against the main weeks. 
Now i need to create the DAX column "NextWeek Hours" which is basically the same as "MainWeek Hours" column but just moved one row up. How do i create the "NextWeek Hours" column DAX based on the existing columns in the table:

EmployeeRosterPeriodMainWeekNumberMainWeekMainWeek HoursNextWeekNextWeek Hours
66272607/04/2024 to 04/05/2024W - 17/04/202423.314/04/202422.9
66272607/04/2024 to 04/05/2024W - 214/04/202422.921/04/202418.9
66272607/04/2024 to 04/05/2024W - 321/04/202418.928/04/202423.9
66272607/04/2024 to 04/05/2024W - 428/04/202423.95/05/202423.0
66272605/05/2024 to 01/06/2024W - 15/05/202423.012/05/202421.2
66272605/05/2024 to 01/06/2024W - 212/05/202421.219/05/202434.3
66272605/05/2024 to 01/06/2024W - 319/05/202434.326/05/202430.2
66272605/05/2024 to 01/06/2024W - 426/05/202430.22/06/202429.3
66272602/06/2024 to 29/06/2024W - 12/06/202429.39/06/20243.0
66272602/06/2024 to 29/06/2024W - 29/06/20243.016/06/2024 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ravelrausch ,

 

Kedar_Pande's workaround is a good way which could solve your issue by  LOOKUPVALUE() function.

You can also try my code to create a calculated column.

NextWeek Hours = 
VAR _NEXTWEEK = 'Table'[NextWeek]
RETURN
CALCULATE(SUM('Table'[MainWeek Hours]),FILTER('Table','Table'[MainWeek] = _NEXTWEEK))

Result is as below.

vrzhoumsft_0-1735529520463.png

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
Poojara_D12
Super User
Super User

Hi @ravelrausch 

Use the LOOKUPVALUE function in DAX to create the NextWeek Hours column. Here's the formula:

 

NextWeek Hours =
LOOKUPVALUE(
    TableName[MainWeek Hours],
    TableName[MainWeek],
    TableName[NextWeek]
)

 

  • Matches the NextWeek column to the MainWeek column.
  • Returns the corresponding MainWeek Hours value.
  • This shifts the hours up by one row to populate NextWeek Hours.

 

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Poojara
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a "Kudos"

Kind Regards,
Poojara - Proud to be a Super User
Data Analyst | MSBI Developer | Power BI Consultant
Consider Subscribing my YouTube for Beginners/Advance Concepts: https://youtube.com/@biconcepts?si=04iw9SYI2HN80HKS
Anonymous
Not applicable

Hi @ravelrausch ,

 

Kedar_Pande's workaround is a good way which could solve your issue by  LOOKUPVALUE() function.

You can also try my code to create a calculated column.

NextWeek Hours = 
VAR _NEXTWEEK = 'Table'[NextWeek]
RETURN
CALCULATE(SUM('Table'[MainWeek Hours]),FILTER('Table','Table'[MainWeek] = _NEXTWEEK))

Result is as below.

vrzhoumsft_0-1735529520463.png

 

Best Regards,
Rico Zhou

 

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! Your query actually solved my issue! Appreciate it!

sanalytics
Super User
Super User

@ravelrausch 
Basically you need to use Earlier concept for creating this column..
I have created a helper column for obtaining your result. Let me know if you want the result without helping column.
Follow below code.

Helping Column = 
RANKX(
    VALUES( 'Table'[MainWeek] ),[MainWeek],,DESC )
Next week Hours = 
CALCULATE(
   SUM( 'Table'[MainWeek Hours] ),
    FILTER( 'Table',
       'Table'[Helping Column] = EARLIER( 'Table'[Helping Column] ) -1
    ) )

 Below result

sanalytics_0-1735287374942.png

 

There is Microsoft documentation and beautiful Matt Alington sir's aricle (https://exceleratorbi.com.au/earlier-vs-earliest-dax/ )for grasping the Earlier Concept.Please go through that.

 

Let me know if you need pbix file.

 

Hope this helps.

 

Regards

sanalytics

 

 



Kedar_Pande
Super User
Super User

@ravelrausch 

Create column:

NextWeek Hours = 
LOOKUPVALUE(
TableName[MainWeek Hours],
TableName[MainWeek],
TableName[NextWeek]
)

Ensure there are no duplicate MainWeek values in your table, as LOOKUPVALUE requires a unique match.

 

💡 If this helped, please give Kudos 👍 or mark it as a Solution .
Best regards,
Kedar
🌐 Connect on LinkedIn

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.

Top Solution Authors