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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PaMa
New Member

output in seconds.

Hello everyone,
I'm not sure if I'm right here.
I've been working with Power BI for a good six months. Since last week I'm stuck on the following scenario in Power Query:
A table consists of several columns including the columns "Time" and "PNR"
The "Time" column has the following format: DD.MM.YYYY hh:mm:ss and the "PNR" column has the format Text.
The "PNR" column contains the same values several times. These values must be compared with the "Time" column and the difference in time to these same values should appear as the result. The result is to be output in seconds.
Can someone help me with this?


Thanks in advance

7 REPLIES 7
PaMa
New Member

It's all a bit cumbersome. So, I sorted by PNR. Now I would like to have the difference between the time and the associated PNR. Can this be created in Power Query via a DAX function?
Unbenannt.JPG

Use this where Source needs to be replaced

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ListPNR = List.Buffer(Source[PNR]),
    ListTime = List.Buffer(Source[Time]),
    CountTbl = Table.RowCount(Source),
    GenResultList = List.Generate(()=>[x=0,i=0], each [i]<CountTbl, each [i=[i]+1, x=if ListPNR{i+1}=ListPNR{i} then List.Max({Duration.From(0), ListTime{i}-ListTime{i+1}}) else 0 ], each try Duration.From([x]) otherwise Duration.From(0)),
    Result = Table.FromColumns(Table.ToColumns(Source) & {GenResultList}, Table.ColumnNames(Source) & {"Difference"})
in
    Result
PaMa
New Member

TimePNR
20.05.2023 20:03:25D625961
20.05.2023 15:04:55D627034
20.05.2023 14:50:51213036
20.05.2023 14:43:56213036
20.05.2023 14:20:25213036
20.05.2023 13:23:43D626093
20.05.2023 12:24:56D573572
20.05.2023 12:21:22D599761
20.05.2023 12:21:19D197163
20.05.2023 12:19:45D564575
20.05.2023 12:03:59213036
20.05.2023 11:56:46213036
20.05.2023 11:56:42D610731
20.05.2023 11:45:47D561089
20.05.2023 11:41:06D638730
20.05.2023 11:36:10D0078374
20.05.2023 11:28:51D658661
20.05.2023 06:54:26D561238
20.05.2023 06:35:35D197163
20.05.2023 06:33:56D599761
20.05.2023 05:38:29D567482
20.05.2023 05:37:30D625929
20.05.2023 05:35:03D626034
20.05.2023 05:34:53D574419
20.05.2023 05:30:49D565712
20.05.2023 05:28:30D599710
20.05.2023 05:22:55D610731
20.05.2023 05:08:41D146049
20.05.2023 04:53:20D568920
20.05.2023 04:51:41D626139
20.05.2023 01:18:34D626393
19.05.2023 23:29:49D153135
19.05.2023 23:04:05D625961
19.05.2023 21:41:37D594069
19.05.2023 21:38:57D211959
19.05.2023 21:35:49D0155647
19.05.2023 21:31:41D197789
19.05.2023 21:28:59D625961
19.05.2023 21:27:10D0211948
19.05.2023 21:17:55D0219576
19.05.2023 21:16:23D574420
19.05.2023 21:14:37D0207420
19.05.2023 21:11:47D0195838
19.05.2023 21:10:53D150295
19.05.2023 21:09:28D0186947
19.05.2023 21:07:53D145905
19.05.2023 21:06:42D569652
19.05.2023 21:06:17D170381
19.05.2023 19:26:11D569196
19.05.2023 19:22:41D626183
19.05.2023 18:32:40D231522
19.05.2023 13:42:49D0221203
19.05.2023 13:28:15D0210293
19.05.2023 13:28:09D569196
19.05.2023 13:27:43D638730
19.05.2023 13:26:13D566158
19.05.2023 13:23:40D626093
19.05.2023 13:22:22D0220141
19.05.2023 13:20:36D667734
19.05.2023 13:20:31D667734
19.05.2023 13:16:16D599714
19.05.2023 13:13:07D0075787
19.05.2023 13:11:59D626034
19.05.2023 13:03:07D231522
19.05.2023 12:59:20D0003336
19.05.2023 12:51:54LK1483
19.05.2023 12:37:48LK3265
19.05.2023 12:25:24D633011
19.05.2023 12:07:19D181146
19.05.2023 12:03:46D625998
19.05.2023 11:59:32LK2703
19.05.2023 11:58:39D565909
19.05.2023 11:48:02D0223793
19.05.2023 11:12:42D172245
19.05.2023 10:48:48D556858
19.05.2023 10:42:50D649162
19.05.2023 10:26:48D0210495
19.05.2023 09:54:20LK1732
19.05.2023 09:48:35D0050667
19.05.2023 09:44:48D639099
19.05.2023 09:36:35D626885

This is how the data is looking like. Can you tell me the expected answer for any row and the logic followed to arrive at the answer?

 

1.png

PaMa
New Member

Unfortunately, the seconds were not copied in the Time column.

PaMa
New Member

Great, Thanks! Here is a small copy of the file

 

 

TimeNr_ZKPNR
20.05.2023 20:03:2501501.01.01D625961
20.05.2023 15:04:5501501.01.01D627034
20.05.2023 14:50:5101501.01.02213036
20.05.2023 14:43:5601501.01.01213036
20.05.2023 14:20:2501501.01.02213036
20.05.2023 13:23:4301501.01.01D626093
20.05.2023 12:24:5601501.01.01D573572
20.05.2023 12:21:2201501.01.01D599761
20.05.2023 12:21:1901501.01.01D197163
20.05.2023 12:19:4501501.01.01D564575
20.05.2023 12:03:5901501.01.02213036
20.05.2023 11:56:4601501.01.01213036
20.05.2023 11:56:4201501.01.01D610731
20.05.2023 11:45:4701501.01.01D561089
20.05.2023 11:41:0601501.01.01D638730
20.05.2023 11:36:1001501.01.01D0078374
20.05.2023 11:28:5101501.01.01D658661
20.05.2023 06:54:2601501.01.01D561238
20.05.2023 06:35:3501501.01.01D197163
20.05.2023 06:33:5601501.01.01D599761
20.05.2023 05:38:2901501.01.01D567482
20.05.2023 05:37:3001501.01.01D625929
20.05.2023 05:35:0301501.01.01D626034
20.05.2023 05:34:5301501.01.01D574419
20.05.2023 05:30:4901501.01.01D565712
20.05.2023 05:28:3001501.01.01D599710
20.05.2023 05:22:5501501.01.01D610731
20.05.2023 05:08:4101501.01.01D146049
20.05.2023 04:53:2001501.01.01D568920
20.05.2023 04:51:4101501.01.01D626139
20.05.2023 01:18:3401501.01.01D626393
19.05.2023 23:29:4901501.01.01D153135
19.05.2023 23:04:0501501.01.01D625961
19.05.2023 21:41:3701501.01.01D594069
19.05.2023 21:38:5701501.01.01D211959
19.05.2023 21:35:4901501.01.01D0155647
19.05.2023 21:31:4101501.01.01D197789
19.05.2023 21:28:5901501.01.01D625961
19.05.2023 21:27:1001501.01.01D0211948
19.05.2023 21:17:5501501.01.01D0219576
19.05.2023 21:16:2301501.01.01D574420
19.05.2023 21:14:3701501.01.01D0207420
19.05.2023 21:11:4701501.01.01D0195838
19.05.2023 21:10:5301501.01.01D150295
19.05.2023 21:09:2801501.01.01D0186947
19.05.2023 21:07:5301501.01.01D145905
19.05.2023 21:06:4201501.01.01D569652
19.05.2023 21:06:1701501.01.01D170381
19.05.2023 19:26:1101501.01.01D569196
19.05.2023 19:22:4101501.01.01D626183
19.05.2023 18:32:4001501.01.01D231522
19.05.2023 13:42:4901501.01.01D0221203
19.05.2023 13:28:1501501.01.01D0210293
19.05.2023 13:28:0901501.01.01D569196
19.05.2023 13:27:4301501.01.01D638730
19.05.2023 13:26:1301501.01.01D566158
19.05.2023 13:23:4001501.01.01D626093
19.05.2023 13:22:2201501.01.01D0220141
19.05.2023 13:20:3601501.01.01D667734
19.05.2023 13:20:3101501.01.01D667734
19.05.2023 13:16:1601501.01.01D599714
19.05.2023 13:13:0701501.01.01D0075787
19.05.2023 13:11:5901501.01.01D626034
19.05.2023 13:03:0701501.01.01D231522
19.05.2023 12:59:2001501.01.01D0003336
19.05.2023 12:51:5401501.01.01LK1483
19.05.2023 12:37:4801501.01.01LK3265
19.05.2023 12:25:2401501.01.01D633011
19.05.2023 12:07:1901501.01.01D181146
19.05.2023 12:03:4601501.01.01D625998
19.05.2023 11:59:3201501.01.01LK2703
19.05.2023 11:58:3901501.01.01D565909
19.05.2023 11:48:0201501.01.01D0223793
19.05.2023 11:12:4201501.01.01D172245
19.05.2023 10:48:4801501.01.01D556858
19.05.2023 10:42:5001501.01.01D649162
19.05.2023 10:26:4801501.01.01D0210495
19.05.2023 09:54:2001501.01.01LK1732
19.05.2023 09:48:3501501.01.01D0050667
19.05.2023 09:44:4801501.01.01D639099
19.05.2023 09:36:3501501.01.01D626885
19.05.2023 09:35:4501501.01.01D231551
19.05.2023 09:35:2301501.01.01D626841
19.05.2023 09:11:1301501.01.01D181693
19.05.2023 09:06:1701501.01.01D197575
19.05.2023 08:42:0501501.01.01D562801
19.05.2023 08:41:0501501.01.01D0201545
19.05.2023 08:40:5401501.01.01D0201545
19.05.2023 08:40:5301501.01.01212537
19.05.2023 08:40:5001501.01.01D0201561
19.05.2023 08:40:4801501.01.01D0201561
19.05.2023 08:37:2401501.01.01D589612
19.05.2023 08:34:3601501.01.01D562759
19.05.2023 08:33:3101501.01.01D0058782
19.05.2023 08:26:1801501.01.01D561133
19.05.2023 08:20:0701501.01.01LK3961
19.05.2023 08:18:5901501.01.01LK0980
19.05.2023 08:17:3101501.01.01D564697
19.05.2023 08:11:2601501.01.01LK10540
19.05.2023 08:10:2601501.01.01LK2703
Vijay_A_Verma
Super User
Super User

Please post some sample data for both columns. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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