Forum Discussion
Jacy
8 years agoFrequent Visitor
OFX CONNECTION
Hello, I need to read a bank file with .OFX extension. I would like to know if there is a api or a native power bi connection for this type of file? Thanks
Cleyton
2 years agoNew Member
Sorry for my bad english
I know it's late but maybe it will help you or others.
I created a script in M-Language to deal with Banco do Brasil's OFX files, without the need for conversions by reading the OFX directly.
Maybe it will serve as inspiration, you can check out the script at the link https://ornit.com.br
let
pFile = "C:\temp\Extrato.ofx",
Fonte = Csv.Document(File.Contents(pFile),[Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Tipo Alterado" = Table.TransformColumnTypes(Fonte,{{"Column1", type text}}),
Mod001 =
Table.ReorderColumns(
Table.FillDown(
Table.ReplaceValue(
Table.AddIndexColumn(
Table.RemoveColumns(
Table.SelectRows(
Table.AddColumn(
Table.TransformColumns(
Table.AddColumn(
Table.AddColumn( Table.SelectRows(#"Tipo Alterado", each Text.Contains([#"Column1"],"<"))
, "Column2", each Text.BetweenDelimiters([Column1],"<",">"), type text)
, "Column3", each Text.AfterDelimiter([Column1],">"), type text)
, {{"Column3", each try Text.BeforeDelimiter(_,"<") otherwise _ , type text}})
, "Column4", each if List.Contains({"SIGNONMSGSRSV1","BANKMSGSRSV1","STMTTRN","LEDGERBAL"},[Column2]) then [Column2] else null, type text)
, each Text.StartsWith(Text.Trim([Column1]) ,"</") = false and [Column1] <> "<OFX>")
, {"Column1"})
, "Column1",1,1)
, each [Column1] , each if [Column4] = null then null else [Column1], Replacer.ReplaceValue, {"Column1"})
, {"Column4","Column1"})
, {"Column1","Column2","Column3","Column4"}),
getData = (dbOFX,pBloco,pID) =>
Table.PromoteHeaders(
Table.Transpose(
Table.SelectRows( dbOFX
, each [Column4] = pBloco and [Column1] = pID and [Column3]<>"")[[Column2],[Column3]])
),
Mod002 =
Table.AddColumn(
Table.Group( Mod001
, {"Column1","Column4"}
, {{"Data", each _, type table [Column1=number, Column2=text, Column3=text, Column4=text]}})
, "Data1", each getData([Data],[Column4],[Column1]), type table)[[Column4],[Data1]]
in
Mod002