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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
stej
Frequent Visitor

Why text is changed even when parsed as text

I try to parse IIS log files. The log files have this structure: 

 

 2017-01-18_21h24_55.png

I load the files from folder, so I combine the files like this

 

2017-01-18_21h27_29.png

 

I select "space" as separator, the line is parsed, but the first column is changed to other format. Why?? 2017-01-18_21h29_51.png

 

The resulting column has type "text", so why is it interpreted as date?

I tried to change my regional settings in PowerBi Desktop, but no luck.

 

And other weird behaviour is when I try to merge the first two columns and make a text date like this

 

2017-01-18_21h36_50.png

click on "Merge column", specify "Space" separator and the result is..

 

2017-01-18_21h39_07.png

 

The seconds are lost. Whe I look into Advanced editor, I see

    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Expanded Table Column1", {{"Column1", type text}, {"Column2", type text}}, "cs-CZ"),{"Column1", "Column2"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"dt")

It's probably somehow related to the cs-CZ culture (where did it came from?), but this imho doesn't explain, why the seconds are lost.

 

Thank you for your attention 🙂 Any help would be appreciated as this are the basics that I'm struggling with and I can't move over it.

2 ACCEPTED SOLUTIONS
Vvelarde
Community Champion
Community Champion

@stej

 

After you Apply the Combine Binaries. In Queries Panel you will find a Folder Name Sample Query and inside of this a Query with the Name Transform Sample Binary From "Your Folder". Select this and go to Advance Editor and change the type date to text.

 

Transform.png

 

 




Lima - Peru

View solution in original post

Hi @stej,

 

You can try to use below formula which used to loop the specified folder and combine the file to one table.

 

let
    LoadCSVFileAndCombine= (FilePath as text) as table => 
    let
        Source = Folder.Files(FilePath),
        #"Filtered Rows" = Table.SelectRows(Source, each [Extension] = ".csv"),
        Custom = Table.SelectColumns(Table.AddColumn(#"Filtered Rows", "Custom", each Csv.Document([Content])),"Custom"),
        Combine= Table.Combine(Custom[Custom])
in
    Combine
in 
    LoadCSVFileAndCombine

 

Use steps:

1. Open query editor

2. Add blank query.

3. Open the advanced editor.

4. Paste above formula.

5. Use folder path to invoke above function.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

9 REPLIES 9
v-shex-msft
Community Support
Community Support

Hi @stej,

 

I'd like to suggest you save the iis log file to csv, then load csv file to query editor.

 

Capture.PNG

 

Then you can choose the specific type of column at "change type" steps.

 

Capture2.PNGCapture3.PNG

 

Full query:

 

let
    Source = Csv.Document(File.Contents("C:\Users\xxxxx\Desktop\Log.csv"),15,"",null,1252),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type time}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", Int64.Type}, {"Column8", type text}, {"Column9", type text}, {"Column10", type text}, {"Column11", type text}, {"Column12", Int64.Type}, {"Column13", Int64.Type}, {"Column14", Int64.Type}, {"Column15", Int64.Type}})
in
    #"Changed Type"

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft yes, that might work probably, But how do I combine more files from the folder together? Note that I don't know their name and count, just the folder path.

Hi @stej,

 

You can try to use below formula which used to loop the specified folder and combine the file to one table.

 

let
    LoadCSVFileAndCombine= (FilePath as text) as table => 
    let
        Source = Folder.Files(FilePath),
        #"Filtered Rows" = Table.SelectRows(Source, each [Extension] = ".csv"),
        Custom = Table.SelectColumns(Table.AddColumn(#"Filtered Rows", "Custom", each Csv.Document([Content])),"Custom"),
        Combine= Table.Combine(Custom[Custom])
in
    Combine
in 
    LoadCSVFileAndCombine

 

Use steps:

1. Open query editor

2. Add blank query.

3. Open the advanced editor.

4. Paste above formula.

5. Use folder path to invoke above function.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft

That also did the trick. I had to change it a little bit and give it custom separator, so the result is this (pasing here mainly for me 😉

 

let
    LoadCSVFileAndCombine= (FilePath as text) as table => 
    let
        Source = Folder.Files(FilePath),
        #"Filtered Rows" = Table.SelectRows(Source, each [Extension] = ".log"),
        Custom = Table.SelectColumns(Table.AddColumn(#"Filtered Rows", "Custom", each Csv.Document([Content], null, " ")),"Custom"),
        Combine= Table.Combine(Custom[Custom]),
        #"Renamed Columns" = Table.RenameColumns(Combine,{{"Column1", "date" }, {"Column2", "time" }, {"Column3", "s-sitename" }, {"Column4", "s-computername" }, {"Column5", "s-ip" }, {"Column6", "cs-method" }, {"Column7", "cs-uri-stem" }, {"Column8", "cs-uri-query" }, {"Column9", "s-port" }, {"Column10", "cs-username" }, {"Column11", "c-ip" }, {"Column12", "cs-version" }, {"Column13", "cs(User-Agent)" }, {"Column14", "cs(Cookie)" }, {"Column15", "cs(Referer)" }, {"Column16", "cs-host" }, {"Column17", "sc-status" }, {"Column18", "sc-substatus" }, {"Column19", "sc-win32-status" }, {"Column20", "sc-bytes" }, {"Column21", "cs-bytes" }, {"Column22", "time-taken" }})
    in
        #"Renamed Columns"
in 
    LoadCSVFileAndCombine

 

Thanks, accepted.

Vvelarde
Community Champion
Community Champion

@stej

 

After you Apply the Combine Binaries. In Queries Panel you will find a Folder Name Sample Query and inside of this a Query with the Name Transform Sample Binary From "Your Folder". Select this and go to Advance Editor and change the type date to text.

 

Transform.png

 

 




Lima - Peru
mike_honey
Memorable Member
Memorable Member

Please post your entire script from the Advanced Editor.

The script looks like this

 

 

let
    Source = Folder.Files("d:\powerbi-test\iis\transformed"),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content"}),
    #"Invoke Custom Function1" = Table.AddColumn(#"Removed Other Columns", "Transform Binary from transformed", each #"Transform Binary from transformed"([Content])),
    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function1", {"Transform Binary from transformed"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform Binary from transformed", Table.ColumnNames(#"Removed Other Columns1"[#"Transform Binary from transformed"]{0}))
in
    #"Expanded Table Column1"

 

and the result

 

2017-01-19_07h35_52.png

That looks like a different function - there's no "Merged Columns" step?

@mike_honey This was without the merge step. 

Wen I apply "Merged columns", the result looks like this:

 

2017-01-20_15h00_10.png

 

And the query is 

 

let
    Source = Folder.Files("d:\powerbi-test\iis2\transformed"),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Content"}),
    #"Invoke Custom Function1" = Table.AddColumn(#"Removed Other Columns", "Transform Binary from transformed", each #"Transform Binary from transformed"([Content])),
    #"Removed Other Columns1" = Table.SelectColumns(#"Invoke Custom Function1", {"Transform Binary from transformed"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform Binary from transformed", Table.ColumnNames(#"Removed Other Columns1"[#"Transform Binary from transformed"]{0})),
    #"Removed Other Columns2" = Table.SelectColumns(#"Expanded Table Column1",{"Column1", "Column2"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Removed Other Columns2", {{"Column1", type text}, {"Column2", type text}}, "cs-CZ"),{"Column1", "Column2"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.