Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The PBIX templates doesn't import the logs if log start date is beyond timeframe selected by users (start, end date) #4

Open
ed7257 opened this issue Dec 9, 2022 · 0 comments

Comments

@ed7257
Copy link

ed7257 commented Dec 9, 2022

The PBIX templates doesn't import the logs if log start date is beyond timeframe selected by users (since, end date)
I adjusted Files table Power Query code to bring the latest log file for each log file type (even when the log file date is outside the Since/End dates range). Please review. M-code:

let
RangeStart = if(SinceDate = null and (NumberDays = null or NumberDays < 0)) then null else if (SinceDate <> null) then DateTime.From(SinceDate) else DateTime.From(Date.AddDays(Date.From(DateTime.LocalNow()), NumberDays * -1)),
RangeEnd = DateTime.From(Date.AddDays(Date.From(DateTime.LocalNow()), 1)),
// FILES SOURCE - Uncomment one of the following lines
Source = #"Files from Disk",
//Source = #"Files from BlobStorage",
// FILES SOURCE
DateFindFromName = Table.AddColumn(Source, "Date2", each if ([Date] = null) then

let
fileName = Text.Lower([Name]),
dateExtract = Text.BeforeDelimiter(Text.AfterDelimiter(fileName, "_", {0, RelativePosition.FromEnd}), "t"),
dateParse = try Date.From(dateExtract) otherwise
let
dateExtract2 = Text.BeforeDelimiter(Text.End(fileName, 22), "."),
dateParse = try Date.From(dateExtract2) otherwise null
in dateParse
in
dateParse

else [Date]),
#"Removed Columns2" = Table.RemoveColumns(DateFindFromName,{"Date"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns2",{{"Date2", "Date"}}),
#"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Date", type date}}),
#"Inserted Text Before Delimiter" = Table.AddColumn(#"Changed Type1", "LogName", each Text.BeforeDelimiter(Text.From([Name], "en-CA"), "2"), type text),
#"Grouped Rows1" = Table.Group(#"Inserted Text Before Delimiter", {"LogName"}, {{"maxdate", each List.Max([Date]), type nullable date}, {"all", each _, type table [Content=binary, Name=text, Extension=text, Date modified=datetime, Folder=text, GatewayId=text, LogName=text, Date=nullable date]}}),
#"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows1", "all", {"Content", "Name", "Extension", "Date modified", "Folder", "GatewayId", "Date"}, {"Content", "Name", "Extension", "Date modified", "Folder", "GatewayId", "Date"}),
#"Added Conditional Column1" = Table.AddColumn(#"Expanded all", "LastLogFileFlag", each if [maxdate] = [Date] then 1 else 0),
#"Changed Type2" = Table.TransformColumnTypes(#"Added Conditional Column1",{{"LastLogFileFlag", Int64.Type}}),
IncrementalFileFilter = Table.SelectRows(#"Changed Type2", each ([Date] = null or RangeStart = null or (DateTime.From([Date]) >= RangeStart and DateTime.From([Date]) < RangeEnd)) or [LastLogFileFlag] = 1),
GatewayFilter = Table.SelectRows(IncrementalFileFilter, each GatewayFilters = null or [GatewayId] = null or Text.Contains(GatewayFilters, [GatewayId]) ) ,
#"Lowercased Text" = Table.TransformColumns(GatewayFilter,{{"Name", Text.Lower, type text}, {"Folder", Text.Lower, type text}}),
#"Grouped Rows" = Table.Group(#"Lowercased Text", {"Name", "GatewayId"}, {{"Rows", each _, type table [Content=binary, Name=text, GatewayId=nullable text, Date=nullable datetime, Folder=text, Content Type=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Last", each Table.SelectRows([Rows], let latest = List.Max([Rows][Date modified]) in each [Date modified] = latest)),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Rows"}),
#"Expanded Last" = Table.ExpandTableColumn(#"Removed Columns1", "Last", {"Content", "Date", "Extension", "Folder"}, {"Content", "Date", "Extension", "Folder"}),
#"Added Conditional Column" = Table.AddColumn(#"Expanded Last", "Content Type", each if Text.StartsWith([Name], "gatewayinfo") then "logs" else if Text.StartsWith([Name], "gatewayerror") then "logs" else if Text.StartsWith([Name], "gatewaynetwork") then "logs" else if Text.Contains([Name], "report") then "reports" else if [Extension] = ".log" then "logs" else if Text.Contains([Name], "gatewayproperties") then "metadata" else if Text.Contains([Name], "gatewayclusters") then "metadata" else "other"),
#"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Extension"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Date", type date}, {"Folder", type text}, {"Content Type", type text}})
in
#"Changed Type"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant