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
neees78
Advocate I
Advocate I

DAX to create job start time based on "Day start time & Duration"

Hello All, 

 

I've the following table - all columns in green are available - entered manually by users

Question 

is there a way to  get "start date per job item" calculated using 'start date day' & 'Dur (hr)'

but sorted by system sequence ,  so the result will be similar to this column in Yellow 
**each new job day starts at 00:00 hrs

 

neees78_0-1638993526690.png

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@neees78 

Add the following calculated column to your table to get the addition of Start date and Duration of previous row:

Start Date Per Job Item = 
VAR __SYS = Table3[System Sequent] 
VAR __LASTSYS = 
    CALCULATE(
        MAX( Table3[System Sequent] ),
        Table3[System Sequent] < __SYS,
        ALLEXCEPT(Table3 , Table3[Event] )
    )
VAR __LASTDUR = 
     CALCULATE(
        SUM( Table3[Dur (hr)] ),
        Table3[System Sequent] <= __LASTSYS,
        ALLEXCEPT(Table3 , Table3[Event] )
    )
RETURN

 Table3[Start Date (day)] +  TIME(__LASTDUR,0,0)

Fowmy_0-1639039124113.png

I formatted the column as follows to show 24hr time

Fowmy_1-1639039142457.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
Fowmy
Super User
Super User

@neees78 

Add the following calculated column to your table to get the addition of Start date and Duration of previous row:

Start Date Per Job Item = 
VAR __SYS = Table3[System Sequent] 
VAR __LASTSYS = 
    CALCULATE(
        MAX( Table3[System Sequent] ),
        Table3[System Sequent] < __SYS,
        ALLEXCEPT(Table3 , Table3[Event] )
    )
VAR __LASTDUR = 
     CALCULATE(
        SUM( Table3[Dur (hr)] ),
        Table3[System Sequent] <= __LASTSYS,
        ALLEXCEPT(Table3 , Table3[Event] )
    )
RETURN

 Table3[Start Date (day)] +  TIME(__LASTDUR,0,0)

Fowmy_0-1639039124113.png

I formatted the column as follows to show 24hr time

Fowmy_1-1639039142457.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@Fowmy  

thanks a lot it worked very well for the test table but the problem I have is that my rows are not in necessarily in order

(Duration is not always going to be previous row)  

 

if the system sequence is used to sort rows  BUT after selecting job-start-day  , then previous row calculation will be correct , I'm not sure if this is achievable !

 

it’s a large table but for a given date day all job item entered as per system sequence

 

example for 1 day record -sorted by resulted calcualted column 

neees78_1-1639138300943.png

same if sorted by sys-sequence 

neees78_2-1639138416597.png

 

ValtteriN
Super User
Super User

Hi,

I am not fully certain I understood your question but, basically what you want to do is to have a calculated column and then sort it based on [system sequency]? There is a functionality called sort by column so 1st you can create a new calculated column and afterwards you can select "sort by column" to sort this calculated column based on the sequency column.

ValtteriN_0-1639037662442.png

 


Hopefully this helps and if it does consider accepting this as a solution!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




The solution provided by @Fowmy seems to be working but on small table  

I need to accomplish two steps  before executing calculation

# select all rows for any given day by Start-job-day time  + Sort by system Seq à  Then calculate column based on Duration

 

But I’m not sure if this is achievable  

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.

Top Solution Authors