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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
LinlookZDJ
Helper I
Helper I

Adding Custom Column

Dear Power BI Experts,

 

I have been stuck in this custom column quite some time and I couldn't figure out the solution.

 

This is my raw file data consist of 3 columns, namely "Start Date Time", "Complete Date Time" and "Machine" as shown in below:

 

MF.jpg

 

I would like to add a custom column to calculate the time gap between each row for different type of machines. (However, i would like to leave first row and last row of individual machine as blank)

 

My desired outcome is as follow:

 

what i want to achieve.jpg

 

Appreciate for your kind assistance and welcome any types of solutions or recommendations. 

 

Thank you for your time in advance!

 

Attached my sample raw file for reference:

https://drive.google.com/file/d/1BzlSpP_YC3fjfSPThbnVcqAbn9GxILVe/view?usp=sharing

 

Best regards

Lin

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@LinlookZDJ 

pls try to create a column

Column = 
VAR _last=maxx(FILTER('Raw File','Raw File'[Complete Date Time]<EARLIER('Raw File'[Complete Date Time])&&'Raw File'[Machine]=EARLIER('Raw File'[Machine])),'Raw File'[Complete Date Time])
return if(ISBLANK(_last)||'Raw File'[Complete Date Time]=CALCULATE(max('Raw File'[Complete Date Time]),ALLEXCEPT('Raw File','Raw File'[Machine])),BLANK(),'Raw File'[Start Date Time]-_last)

pls see the attachment below

 





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

Proud to be a Super User!




View solution in original post

4 REPLIES 4
ryan_mayu
Super User
Super User

@LinlookZDJ 

pls try to create a column

Column = 
VAR _last=maxx(FILTER('Raw File','Raw File'[Complete Date Time]<EARLIER('Raw File'[Complete Date Time])&&'Raw File'[Machine]=EARLIER('Raw File'[Machine])),'Raw File'[Complete Date Time])
return if(ISBLANK(_last)||'Raw File'[Complete Date Time]=CALCULATE(max('Raw File'[Complete Date Time]),ALLEXCEPT('Raw File','Raw File'[Machine])),BLANK(),'Raw File'[Start Date Time]-_last)

pls see the attachment below

 





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

Proud to be a Super User!




Hi Ryan,

 

Just to check if there is anyways i can add the custom column inside transform data? As my raw data size is very big, so adding the new column in data view page is very lagging and it will hang easily.

 

Best regards

Lin

@LinlookZDJ 

you are welcome. I am not sure if we can do that in PQ. Maybe someone else can provide better solution for you.





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

Proud to be a Super User!




Hi Ryan,

 

Thanks for the solution! It works!

 

Best regards

Lin

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.