我有一个查询数据表,该数据表已合并为Power查询。结果是每个人在两年中的月度百分比看起来像这样。我想在月份结束后动态从桌子上删除几个月。因此,从8月1日开始,当我刷新时,将从电源查询表中删除。
合并查询表:
名称 |
Jul-21 |
Aug-21 |
sept-21 |
bob |
.10 |
.20 |
.20 .10 |
Amy |
.30 |
.40 |
.10 |
我已经浏览了stackover,并且有一篇文章与我想完成的事情相似: tate.table.removecolumns基于日期
该帖子中建议的代码以删除三岁以上的列标题是:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.From(_) >= Date.AddYears(Date.From(DateTime.FixedLocalNow()),-3)
otherwise true))
in
final
我进入了高级编辑器中:我进入了高级编辑器中电源查询以尝试将其调整为我要执行的操作,但是代码不起作用,也没有删除列。这甚至是在调整代码以不删除本月之前。
let
Source = Table.Combine({Merge1, Merge2}),
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.FromText(_) >= Date.From(DateTime.FixedLocalNow())
otherwise true))
in
final
我已经尝试了每个尝试date.from(_)和每个尝试日期。在我的任何测试中,我尚未更改 date.from(dateTime.fixedLocalNow())方程的一部分。
我试图搜索在线资源,以了解该代码的工作原理以及使用Microsoft的支持网站来了解Table.SelectColumns和List.Select。代码,因此使我很难理解我需要做出的更改才能使它起作用。
到目前为止,我了解 list.Select 正在确定将包含在 table.selectcolumns 函数中的列。 list.Select 正在创建所有列标题的列表,然后在当前日期测量其文本(由 date.fromtext(_)函数转换为日期)使用每个尝试和,否则正在捕获所有非日期标头,并确保它们也包括在内。
但是我不明白为什么该方程不会删除任何过去的日期列,或者如何调整功能(一旦起作用)以不删除当前月。感谢这两个问题的任何帮助。如果有帮助,我可以共享指向完整电子表格的链接。
I have a query table of data that has been merged in Power Query. The result is monthly percentages for each person for two years that looks like this. I would like to dynamically remove months from the table when the month is over. So, starting August 1st, July would be removed from the power query table when I refresh it.
Merged Query Table:
Name |
Jul-21 |
Aug-21 |
Sept-21 |
Bob |
.10 |
.20 |
.10 |
Amy |
.30 |
.40 |
.10 |

I've looked through StackOver, and there is one post that is similar to what I want to accomplish: Table.RemoveColumns based on the date
The code suggested in that post to remove column headers older than three years was:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.From(_) >= Date.AddYears(Date.From(DateTime.FixedLocalNow()),-3)
otherwise true))
in
final
I went into the Advanced Editor in Power Query to try to adjust it to what I was trying to do, but the code does not work and no columns are removed. This is even before adjusting the code to not remove the current month.
let
Source = Table.Combine({Merge1, Merge2}),
final = Table.SelectColumns(Source, List.Select(Table.ColumnNames(Source),
each try Date.FromText(_) >= Date.From(DateTime.FixedLocalNow())
otherwise true))
in
final
I have tried both each try Date.From(_) and each try Date.FromText(_), neither of which removed any columns. I have not altered the Date.From(DateTime.FixedLocalNow()) part of the equation in any of my tests.
I have tried to search for online resources to understand how this code works as well as used Microsoft's support site to learn about Table.SelectColumns and List.Select, but I have yet to find a good resource that can break down how to understand the above code, so it makes it difficult for me to understand what changes I need to make to get it work.
So far, I understand that the List.Select is determining the columns that will be included in the Table.SelectColumns function. List.Select is creating a list of all the column headers and then measuring their text (transformed by the Date.FromText(_) function into a date) against the current date using the each try and the otherwise is catching all the non-date headers and making sure they are included as well.
But I don't understand why the equation isn't removing any the past date columns or how to adjust the function (once it works) to not remove the current month. I would appreciate any assistance with both of these questions. I can share a link to the full spreadsheet if that would be helpful.
发布评论
评论(1)
怎么样
How about