The offset 0 is invalid for log file .xel Specify an offset that exists in the log file First of all, I am not DBA but I have to perform some DBA jobs. I am trying to read an extended file using,

  SELECT [object_name],[event_data],[file_name],[file_offset],[Event_Time] 
  FROM OPENQUERY(MyServer,'master.dbo.READ_AUDIT @P_RootFile_Name=''Path\DDL*.xel'',@P_File_Name=''Path\file.xel'',@P_Offsit=0')


I am getting this error,

The offset 0 is invalid for log file .xel  Specify an offset that exists in the log file


How do I calculate the offset of a xel file?

ALTER proc [dbo].[READ_AUDIT] @P_RootFile_Name NvarChar(260),@P_File_Name NvarChar(260)=NULL,@P_Offsit bigint =NULL
as

Select * from 
(
select *,



DATEADD(mi, DATEDIFF(mi, GETUTCDATE(), GETDATE()), CONVERT (XML, event_data).value('(/event/@timestamp)[1]', 'datetime2')) Event_Time
from sys.fn_xe_file_target_read_file(@P_RootFile_Name, null, @P_File_Name, @P_Offsit) 



) as T



order by T.Event_Time ASC
From this post https://docs.microsoft.com/en-us/sql/relational-databases/system-functions/sys-fn-xe-file-target-read-file-transact-sql?view=sql-server-ver15

I have found out that initial_file_name and initial_offset should be null initially