March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I have dynamically combined source files in power query and as a result is creates a source.name column which are the file names for each row, and it my case is the date the file was created. I was to replace the values in this column with a generic naming convention. However, the values in that column will change daily when the source files get refreshed with a new extract date. Is there a way in adanced editor to set this up? I tried to use the code below but it didin't work as needed.
LW = Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()),-7),"MMddyy"),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","inventory_"& LW &".csv","LW",Replacer.ReplaceValue,{"Source.Name"})
An example of the column values, to which the date suffix will change.
Solved! Go to Solution.
Please consider what is the expected result. Based on the script, it looks like your intent is to check to see if the file name includes the date for last week, and if so, replace the Source.Name value with only the formatted version of the date (MMddyy). If that really is your intent, then there are other ways of going this transformation that are more straight-forward. If that is not your intent, then I think the exlaination below will provide you with the insight needed to customize the script provided to meet your actual needs.
Your script says...
Table.ReplaceValue(#"Changed Type","inventory_"& LW &".csv","LW",Replacer.ReplaceValue,{"Source.Name"})
If LW = "052424", then your script translates to:
If the intent is to replace instances of "inventory_052424.csv" with the value of the variable LW, then your script will need to be revised to what is shown below, however, that does mean that if the replacement is made and if there are other values in rows, then your column values will be inconsistent with each other. Some will have a file name convention (like including the .csv) and others will just have the formatted date portion.
Table.ReplaceValue(Source, each [Source.Name], each if [Source.Name] = "inventory_" & LW & ".csv" then LW else [Source.Name], Replacer.ReplaceValue,{"Source.Name"})
When each row in a table needs to be evaluated and then conditionally modified, the 'each' keyword must be present to make that happen (in this circumstance). The Table.ReplaceValue function does not include a row-by-row evaluation by default; for efficiency, it evaluates a list of old values against a list of new values.
Syntax:
Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table
If you still need more assistance, please provide an explaination or example of the expected value. Thanks!
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Please consider what is the expected result. Based on the script, it looks like your intent is to check to see if the file name includes the date for last week, and if so, replace the Source.Name value with only the formatted version of the date (MMddyy). If that really is your intent, then there are other ways of going this transformation that are more straight-forward. If that is not your intent, then I think the exlaination below will provide you with the insight needed to customize the script provided to meet your actual needs.
Your script says...
Table.ReplaceValue(#"Changed Type","inventory_"& LW &".csv","LW",Replacer.ReplaceValue,{"Source.Name"})
If LW = "052424", then your script translates to:
If the intent is to replace instances of "inventory_052424.csv" with the value of the variable LW, then your script will need to be revised to what is shown below, however, that does mean that if the replacement is made and if there are other values in rows, then your column values will be inconsistent with each other. Some will have a file name convention (like including the .csv) and others will just have the formatted date portion.
Table.ReplaceValue(Source, each [Source.Name], each if [Source.Name] = "inventory_" & LW & ".csv" then LW else [Source.Name], Replacer.ReplaceValue,{"Source.Name"})
When each row in a table needs to be evaluated and then conditionally modified, the 'each' keyword must be present to make that happen (in this circumstance). The Table.ReplaceValue function does not include a row-by-row evaluation by default; for efficiency, it evaluates a list of old values against a list of new values.
Syntax:
Table.ReplaceValue(table as table, oldValue as any, newValue as any, replacer as function, columnsToSearch as list) as table
If you still need more assistance, please provide an explaination or example of the expected value. Thanks!
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Yes, thank you! I got it working is the first code you provided.
Hi @negbc - Have you had a chance to see if this works for you? Please consider clicking Accept as Solution if this answered your question. Thanks!
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hi @negbc ,
Please try:
Table.TransformColumns(#"Changed Type",{"Source.Name", each "inventory_"& LW &".csv"})
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum -- China Power BI User Group
How would that work if I needed to replace "inventory_"& LW &".csv" with "LW"?
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.