Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
This is my code
let
Source = Excel.Workbook(File.Contents("C:\Users\KUNTALSINGH\Box\PepsiCo - NA Process Session\ACL_Input.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Scripts", type text}, {"Vendor", Int64.Type}, {"VendorName", type text}, {"BusinessArea", type any}, {"CompanyCode", type text}, {"FiscalYear", Int64.Type}, {"DocumentType", type text}, {"DocumentDate", type date}, {"PostingKey", Int64.Type}, {"PostingDate", type date}, {"DocumentNumber", Int64.Type}, {"Reference", type text}, {"Amountindoccurr", type number}, {"DocumentCurrency", type text}, {"Amountinlocalcurr", type number}, {"LocalCurrency", type text}, {"ClearingDocument", Int64.Type}, {"ClearingDate", type text}, {"Text", type text}, {"NetDueDate", type text}}),
#"Added Custom"= Table.AddColumn(#"Changed Type", "NewColumn",
each if [DocumentType] = "ZA" and [Text] <> "" then
Text.Combine({[DocumentType], [Text], Number.ToText(Number.Abs([Amountindoccurr]))})
else if [DocumentType] = "RE" and [Reference] <> "" then
Text.Combine({[DocumentType], [Reference], Number.ToText(Number.Abs([Amountindoccurr]))})
else
""
),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"NewColumn", type text}}),
#"Add Custom1" = Table.AddColumn(#"Changed Type1", "Condition", each
if Text.StartsWith([NewColumn], "RE") then
List.Count(List.Select(#"Changed Type1"[NewColumn], each Text.Replace([NewColumn], "RE", "ZA") = _))
else if Text.StartsWith([NewColumn], "ZA") then
List.Count(List.Select(#"Changed Type1"[NewColumn], each Text.Replace([NewColumn], "ZA", "RE") = _))
else
null
)
in
#"Add Custom1"
I am getting error
Expression.Error: We cannot apply field access to the type Text.
Details:
Value=RE6727721V95.51
Key=NewColumn
Scripts | Vendor | VendorName | BusinessArea | CompanyCode | FiscalYear | DocumentType | DocumentDate | PostingKey | PostingDate | DocumentNumber | Reference | Amountindoccurr | DocumentCurrency | Amountinlocalcurr | LocalCurrency | ClearingDocument | ClearingDate | Text | NetDueDate | MatchCheck |
S(60-87)-4 | 2000011432 | IOWA ROTOCAST PLASTICS INC | US24 | 2024 | ZA | 26-06-2024 | 31 | 28-06-2024 | 5500148255 | TPM0000003072664 | -2000 | USD | -2000 | USD | TPM0000003072664 | 7/4/2024 | ||||
S(60-87)-5 | 2000011280 | NORTH STAR MARKETING INC | US24 | 2023 | ZA | 01-09-2023 | 31 | 05-09-2023 | 5500235337 | TPM0000003002117 | -1000 | USD | -1000 | USD | 2000022005 | 9/10/2023 | TPM0000003002117 | 9/9/2023 | ||
S(87-100)-5 | 2000204291 | BEVOLUTION GROUP (Corporate) | US24 | 2024 | ZA | 02-06-2024 | 31 | 05-06-2024 | 5500130371 | 994623021 | -5882.1 | USD | -5882.1 | USD | 994623021 | 6/15/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US24 | 2024 | ZA | 01-04-2024 | 31 | 04-04-2024 | 5500084065 | 813581021 | -7347.6 | USD | -7347.6 | USD | 813581021 | 7/26/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US02 | 2024 | ZA | 16-02-2024 | 31 | 20-02-2024 | 5500029608 | 233740021 | -9655.8 | USD | -9655.8 | USD | 233740021 | 6/10/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US04 | 2024 | ZA | 14-05-2024 | 31 | 16-05-2024 | 5500024637 | 261572021 | -9655.8 | USD | -9655.8 | USD | 261572021 | 9/6/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US24 | 2024 | ZA | 07-03-2024 | 31 | 09-03-2024 | 5500051722 | 269201021 | -9655.8 | USD | -9655.8 | USD | 269201021 | 6/30/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US02 | 2024 | ZA | 03-05-2024 | 31 | 07-05-2024 | 5500061524 | 377342021 | -9655.8 | USD | -9655.8 | USD | 377342021 | 8/26/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US02 | 2024 | ZA | 09-05-2024 | 31 | 14-05-2024 | 5500055226 | 478062021 | -9655.8 | USD | -9655.8 | USD | 478062021 | 9/2/2024 | ||||
S(87-100)-5 | 2000027747 | PLASTIPAK PACKAGING | US02 | 2024 | ZA | 20-06-2024 | 31 | 22-06-2024 | 5500079066 | 535163021 | -9655.8 | USD | -9655.8 | USD | 535163021 | 10/13/2024 |
Solved! Go to Solution.
@KuntalSingh well, if you really want to use that key (type + some text columns + amount) and count the number of matching rows then try this after #"Changed Type" step:
key= Table.AddColumn(
#"Changed Type", "Name",
each if [DocumentType] = "ZA" and [Text] <> ""
then Text.Combine({[DocumentType], [Text], Number.ToText(Number.Abs([Amountindoccurr]))})
else
if [DocumentType] = "RE" and [Reference] <> ""
then Text.Combine({[DocumentType], [Reference], Number.ToText(Number.Abs([Amountindoccurr]))})
else ""
),
dict = Record.FromTable(Table.Group(key, "Name", {"Value", Table.RowCount})),
rep = [RE = "ZA", ZA = "RE"],
check = Table.AddColumn(
key,
"Condition",
(x) => Record.FieldOrDefault(dict, Text.Replace(x[Name], x[DocumentType], Record.Field(rep, x[DocumentType])))
)
in
check
I have run this code and do not face any error, it might be because of your column heder if you extract data from severl files
This is my code
let
Source = Excel.Workbook(File.Contents("C:\Users\KUNTALSINGH\Box\PepsiCo - NA Process Session\ACL_Input.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Scripts", type text}, {"Vendor", Int64.Type}, {"VendorName", type text}, {"BusinessArea", type any}, {"CompanyCode", type text}, {"FiscalYear", Int64.Type}, {"DocumentType", type text}, {"DocumentDate", type date}, {"PostingKey", Int64.Type}, {"PostingDate", type date}, {"DocumentNumber", Int64.Type}, {"Reference", type text}, {"Amountindoccurr", type number}, {"DocumentCurrency", type text}, {"Amountinlocalcurr", type number}, {"LocalCurrency", type text}, {"ClearingDocument", Int64.Type}, {"ClearingDate", type text}, {"Text", type text}, {"NetDueDate", type text}}),
#"Added Custom"= Table.AddColumn(#"Changed Type", "NewColumn",
each if [DocumentType] = "ZA" and [Text] <> "" then
Text.Combine({[DocumentType], [Text], Number.ToText(Number.Abs([Amountindoccurr]))})
else if [DocumentType] = "RE" and [Reference] <> "" then
Text.Combine({[DocumentType], [Reference], Number.ToText(Number.Abs([Amountindoccurr]))})
else
""
),
#"Add Custom1" = Table.AddColumn(
#"Added Custom",
"Condition",
each
if Text.StartsWith([NewColumn], "RE") then
let
NewColumnAdj = Text.Replace([NewColumn], "RE", "ZA")
in
List.Count(List.Select(#"Added Custom"[NewColumn], each NewColumnAdj = _))
else if Text.StartsWith([NewColumn], "ZA") then
let
NewColumnAdj = Text.Replace([NewColumn], "ZA", "RE")
in
List.Count(List.Select(#"Added Custom"[NewColumn], each NewColumnAdj = _))
else
null,
Int64.Type // specify column type
)
in
#"Add Custom1"
it does work for me again as bellow image
can you share the image of your error?
I am not getting any error. It took time to load file size inceases from MB to GB's. It is keeps on loading from last 15 mins
Ok. I thought you were having an error, I am going to look at the code and optimize it soon, just let me know how many rows are in your Excel file.
Thanks for your prompt response!
There are near around 70 K rows.
It is not to much but your formula for the condition column is not efficient as it going to apply a filter over all 70K rows, use the next formula, in this case, the result of the previous steps are summarized by group by (changed the row number from 70 k to lower rows), then this table is used for calculation of condition
let
Source = Excel.Workbook(File.Contents("C:\Users\n11472235\OneDrive - Queensland University of Technology\Desktop\qook2.xlsx"), null, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Scripts", type text}, {"Vendor", Int64.Type}, {"VendorName", type text}, {"BusinessArea", type any}, {"CompanyCode", type text}, {"FiscalYear", Int64.Type}, {"DocumentType", type text}, {"DocumentDate", type date}, {"PostingKey", Int64.Type}, {"PostingDate", type date}, {"DocumentNumber", Int64.Type}, {"Reference", type text}, {"Amountindoccurr", type number}, {"DocumentCurrency", type text}, {"Amountinlocalcurr", type number}, {"LocalCurrency", type text}, {"ClearingDocument", Int64.Type}, {"ClearingDate", type text}, {"Text", type text}, {"NetDueDate", type text}}),
#"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"DocumentType", "Reference", "Amountindoccurr", "Text"}),
#"Added Custom"= Table.AddColumn(#"Removed Other Columns", "NewColumn",
each if [DocumentType] = "ZA" and [Text] <> "" then
Text.Combine({[DocumentType], [Text], Number.ToText(Number.Abs([Amountindoccurr]))})
else if [DocumentType] = "RE" and [Reference] <> "" then
Text.Combine({[DocumentType], [Reference], Number.ToText(Number.Abs([Amountindoccurr]))})
else
""
),
#"Grouped Rows" = Table.Group(#"Added Custom", {"NewColumn"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Add Custom1" = Table.AddColumn(#"Added Custom", "Condition", each try #"Grouped Rows"{[NewColumn=(if Text.StartsWith([NewColumn], "RE") then Text.Replace([NewColumn], "RE", "ZA") else if Text.StartsWith([NewColumn], "ZA") then Text.Replace([NewColumn], "ZA", "RE") else null)]}[Count] otherwise null)
in
#"Add Custom1"
I tried the this code as well. It's keep on running since 12 PM till now. so this soluntion dos't work
@KuntalSingh well, if you really want to use that key (type + some text columns + amount) and count the number of matching rows then try this after #"Changed Type" step:
key= Table.AddColumn(
#"Changed Type", "Name",
each if [DocumentType] = "ZA" and [Text] <> ""
then Text.Combine({[DocumentType], [Text], Number.ToText(Number.Abs([Amountindoccurr]))})
else
if [DocumentType] = "RE" and [Reference] <> ""
then Text.Combine({[DocumentType], [Reference], Number.ToText(Number.Abs([Amountindoccurr]))})
else ""
),
dict = Record.FromTable(Table.Group(key, "Name", {"Value", Table.RowCount})),
rep = [RE = "ZA", ZA = "RE"],
check = Table.AddColumn(
key,
"Condition",
(x) => Record.FieldOrDefault(dict, Text.Replace(x[Name], x[DocumentType], Record.Field(rep, x[DocumentType])))
)
in
check
Can you please help on one more logic
Reference | Amountindoccurr | Column1 | Remove Alphapets | Sumif Amount | Amountcopy |
128404JAIMES | -5400 | 1284045400 | 5400 | ||
128404JAIMES | 5400 | 1284045400 | 5400 | ||
7001587798 | 7975.5 | 1284047975.5 | High Priority | 7975.5 | |
7001587798 | 7975.5 | 1284047975.5 | High Priority | 7975.5 | |
7001587798 | 7975.5 | 1284047975.5 | High Priority | 7975.5 | |
11332716 | -5018.4 | 1284045018.4 | 5018.4 | ||
11332716 | -5018.4 | 1284045018.4 | 5018.4 | ||
-10036.8 | 12840410036.8 | 10036.8 |
Please help on one more logic
same number in CC column have + and -
value in Amountindoccurr column means nullyfi then comment is blank and same number in CC column have same value either + or - in Amountindoccurr column then comment is Highy priority
Excel formula
1.Apply formula in Column CC to remove alphabets from Reference(L Column) AND Concatenate with ABS(amt docu currency) after Please implement your logic to get the output
Scripts | Vendor | VendorName | BusinessArea | CompanyCode | FiscalYear | DocumentType | DocumentDate | PostingKey | PostingDate | DocumentNumber | Reference | Amountindoccurr | DocumentCurrency | Amountinlocalcurr | LocalCurrency | ClearingDocument | ClearingDate | Text | NetDueDate | Concatenation | CC |
S(25-60)-1 | 2004235596 | G&G OUTFITTERS INC | US05 | 2024 | RE | 45331 | 31 | 45530 | 5.1E+09 | 242772 | -166.75 | USD | -166.75 | USD | 4/9/2024 | 51001530992024US05 | 242772166.75 | ||||
S(25-60)-1 | 2000011986 | G&G OUTFITTERS INC | US05 | 2024 | RE | 45331 | 31 | 45338 | 5.1E+09 | 242772 | -166.75 | USD | -166.75 | USD | 2000546772 | 4/14/2024 | 4/9/2024 | 51000427342024US05 | 242772166.75 | ||
S(25-60)-1 | 2003871958 | CINTAS CORPORATION N | US01 | 2024 | RE | 45293 | 31 | 45530 | 5.1E+09 | 4178789859 | -205.94 | USD | -205.94 | USD | 3/2/2024 | 51018370002024US01 | 4178789859205.94 | ||||
S(25-60)-1 | 2000029014 | CINTAS CORPORATION 100 | US01 | 2024 | RE | 45293 | 31 | 45510 | 5.1E+09 | 4178789859 | -205.94 | USD | -205.94 | USD | 3/2/2024 | 51005247402024US01 | 4178789859205.94 | ||||
S(25-60)-1 | 2003871958 | CINTAS CORPORATION N | US01 | 2024 | RE | 45307 | 31 | 45530 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 3/16/2024 | 51000625092024US01 | 4180383750209.39 | ||||
S(25-60)-1 | 2000011956 | CINTAS CORPORATION NO 2 | US01 | 2024 | RE | 45307 | 31 | 45506 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 3/16/2024 | 51009005242024US01 | 4180383750209.39 | ||||
S(25-60)-2 | 2000014020 | NYSCO PRODUCTS LLC | US05 | 2024 | RE | 44592 | 21 | 45530 | 5.1E+09 | 0236725-IN | 91.4 | USD | 91.4 | USD | VR:Full Accrual | 4/1/2022 | 51008240022024US05 | 0236725-IN91.4 | |||
S(25-60)-2 | 2000014020 | NYSCO PRODUCTS LLC | US05 | 2024 | RE | 44592 | 31 | 45457 | 5.1E+09 | 0236725-IN | -91.4 | USD | -91.4 | USD | 51010235452024US05 | 0236725-IN91.4 | |||||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45007 | 21 | 45530 | 5.1E+09 | 9648709799 | 217.97 | USD | 217.97 | USD | VR:Pay-as-billed | 7/20/2023 | 51003365112024US01 | 9648709799217.97 | |||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45007 | 31 | 45422 | 5.1E+09 | 9648709799 | -217.97 | USD | -217.97 | USD | VR:Pay-as-billed | 7/20/2023 | 51012950142024US01 | 9648709799217.97 | |||
S(25-60)-2 | 2004015811 | CINTAS CORPORATION N | US05 | 2024 | RE | 45281 | 31 | 45530 | 5.1E+09 | I312210921 | -234.72 | USD | -234.72 | USD | VR:Pay-as-billed | 2/19/2024 | 51024855002024US05 | I312210921234.72 | |||
S(25-60)-2 | 2000031331 | CINTAS FIRE PROTECTION | US24 | 2024 | RE | 45281 | 21 | 45320 | 5.1E+09 | I312210921 | 234.72 | USD | 234.72 | USD | 100831507 | 4/3/2024 | VR:Pay-as-billed | 2/19/2024 | 51000080072024US24 | I312210921234.72 | |
S(25-60)-2 | 2000031331 | CINTAS FIRE PROTECTION | US24 | 2024 | RE | 45281 | 31 | 45299 | 5.1E+09 | I312210921 | -234.72 | USD | -234.72 | USD | 100831507 | 4/3/2024 | VR:Pay-as-billed | 2/19/2024 | 51000540022024US24 | I312210921234.72 | |
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45281 | 31 | 45530 | 5.1E+09 | 9943375106 | -207.97 | USD | -207.97 | USD | 4/19/2024 | 51003750022024US01 | 9943375106207.97 | ||||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2023 | RE | 45281 | 31 | 45288 | 5.1E+09 | 9943375106 | -207.97 | USD | -207.97 | USD | 4/19/2024 | 51013625832023US01 | 9943375106207.97 | ||||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45281 | 31 | 45457 | 5.1E+09 | 9943375106 | -207.97 | USD | -207.97 | USD | 4/19/2024 | 51011440152024US01 | 9943375106207.97 | ||||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45281 | 21 | 45488 | 5.1E+09 | 9943375106 | 207.97 | USD | 207.97 | USD | MR8M | 4/19/2024 | 51005320102024US01 | 9943375106207.97 | |||
S(25-60)-2 | 2000022228 | W W GRAINGER | US01 | 2024 | RE | 45281 | 21 | 45427 | 5.1E+09 | 9943375106 | 207.97 | USD | 207.97 | USD | MR8M | 4/19/2024 | 51006805052024US01 | 9943375106207.97 | |||
S(25-60)-2 | 2003871958 | CINTAS CORPORATION N | US01 | 2024 | RE | 45307 | 31 | 45530 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 3/16/2024 | 51000625092024US01 | 4180383750209.39 | ||||
S(25-60)-2 | 2000011956 | CINTAS CORPORATION NO 2 | US01 | 2024 | RE | 45307 | 31 | 45506 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 3/16/2024 | 51009005242024US01 | 4180383750209.39 | ||||
S(25-60)-2 | 2000011956 | CINTAS CORPORATION NO 2 | US01 | 2024 | RE | 45307 | 21 | 45507 | 5.1E+09 | 4180383750 | 209.39 | USD | 209.39 | USD | MR8M | 3/16/2024 | 51014410102024US01 | 4180383750209.39 | |||
S(25-60)-2 | 2000011956 | CINTAS CORPORATION NO 2 | US01 | 2024 | RE | 45307 | 31 | 45507 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 2000118010 | 8/4/2024 | 3/16/2024 | 51005250672024US01 | 4180383750209.39 | ||
S(25-60)-2 | 2000011956 | CINTAS CORPORATION NO 2 | US01 | 2024 | RE | 45307 | 21 | 45507 | 5.1E+09 | 4180383750 | 209.39 | USD | 209.39 | USD | 2000118010 | 8/4/2024 | MR8M | 3/16/2024 | 51008885072024US01 | 4180383750209.39 | |
S(25-60)-2 | 2000029014 | CINTAS CORPORATION 100 | US01 | 2024 | RE | 45307 | 31 | 45510 | 5.1E+09 | 4180383750 | -209.39 | USD | -209.39 | USD | 3/16/2024 | 51004805942024US01 | 4180383750209.39 |
Perfect! Thank you very much for your kind support 🙂
Hi @KuntalSingh
Try updating the last step #"Add Custom1" as follows:
#"Add Custom1" = Table.AddColumn(
#"Changed Type1",
"Condition",
each
if Text.StartsWith([NewColumn], "RE") then
let
NewColumnAdj = Text.Replace([NewColumn], "RE", "ZA")
in
List.Count(List.Select(#"Changed Type1"[NewColumn], each NewColumnAdj = _))
else if Text.StartsWith([NewColumn], "ZA") then
let
NewColumnAdj = Text.Replace([NewColumn], "ZA", "RE")
in
List.Count(List.Select(#"Changed Type1"[NewColumn], each NewColumnAdj = _))
else
null,
Int64.Type // specify column type
)
The issue was that within List.Select, the field reference [NewColumn] doesn't refer to the field [NewColumn] in the record corresponding to the current row, but rather it tries to refer to the field [NewColumn] of the current items in the list (which is the list of values int he column #"Changed Type1"[NewColumn].
The code above fixes this by placing Text.Replace([NewColumn],...) outside List.Select and storing in NewColumnAdj.
Does this work as intended?
Thank you very much for your prompt support
I have more than 65 K rows data and it takes time to load data. Please assist how to load data faster