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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.