0

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")

1
  • The above isn't DAX, it's Power Query.
    – Sam Nseir
    Commented Nov 19 at 15:31

2 Answers 2

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.

1
  • Thank you, but somehow this resulted in an merged query?
    – Yolanda CB
    Commented Nov 19 at 17:28
1

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())

enter image description here

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

enter link description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.