Dax Add column based on date - Stack Overflow

I want to generate a column. that shows as YTD if the date is the last day of the previous month or bef

I want to generate a column. that shows as YTD if the date is the last day of the previous month or before and FCT otherwise.

This Dax code is giving me errors.

First tried Today() and then realised that's not what I want :)

Added Custom" = Table.AddColumn(#"Change Type4","YTD Date", each if [Date.Custom] <= Today() then "YTD" else "FCT")

I want to generate a column. that shows as YTD if the date is the last day of the previous month or before and FCT otherwise.

This Dax code is giving me errors.

First tried Today() and then realised that's not what I want :)

Added Custom" = Table.AddColumn(#"Change Type4","YTD Date", each if [Date.Custom] <= Today() then "YTD" else "FCT")

Share Improve this question edited Nov 19, 2024 at 14:18 Máté Juhász 2,3252 gold badges24 silver badges44 bronze badges asked Nov 19, 2024 at 13:35 Yolanda CBYolanda CB 156 bronze badges 1
  • The above isn't DAX, it's Power Query. – Sam Nseir Commented Nov 19, 2024 at 15:31
Add a comment  | 

2 Answers 2

Reset to default 1

Try the following:

= Table.AddColumn(#"Changed Type", "YTD Date", each if 
  DateTime.Date([Date]) <= DateTime.Date(
    Date.EndOfMonth(
      Date.AddMonths(
        DateTime.FixedLocalNow(), -1
      )
    )
  ) then "YTD" else "FCT")
  • Get current date/time
  • Subtract a month
  • Get the last date of the month
  • Convert both sides to dates

For what it is worth, you can do similar in DAX via EOMONTH function.

In power query, we don't use today() function to get current date you can try this below function to get current date

= Date.From(DateTime.LocalNow())

then replace the formula with your today() function in your M coding and have a try

enter link description here

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745558324a4632953.html

相关推荐

  • Dax Add column based on date - Stack Overflow

    I want to generate a column. that shows as YTD if the date is the last day of the previous month or bef

    18小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信