Forum Discussion

Tlotly's avatar
Tlotly
Helper V
5 years ago
Solved

Create a custom column containing a variable

Good day

Please assist.

 

How do I create a column in powerquery with the following DAX?

DefaultYear = if(YEAR(TODAY()) = 'Branch Scores'[FinYear],
"DefaultYear"
,
'Branch Scores'[FinYear])

 

 

Kind regards

 

6 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    You can try this expression in a custom column, assuming your FinYear column is type date.

     

    = if [FinYear] = Date.From(DateTime.LocalNow()) then "Default Year" else [FinYear]

     

    Pat

     

    • Tlotly's avatar
      Tlotly
      Helper V

      mahoneypat  Thank you. I tried the above code but it doesn't work for financial dates since my slicer is based on the financial period.  E.g. My Financial dates are from July to June so when I get to 01 July 2021, it will still default to 2021 as the code you sent is comparing to today. I will want that to default to the new financial year which will be 2022.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Try this:

    DefaultYear = Table.AddColumn (PriorStepName, "Year", each if Date.IsInCurrentYear([FinYear]) then "DefaultYear" else [FinYear])
     
    --Nate
    ,
    'Branch Scores'[FinYear])

     

    • Tlotly's avatar
      Tlotly
      Helper V

      Anonymous  Thank you. It's complaining about PriorStepName not being recognised. 

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    PriorStepName should be replaced with YOUR actual prior step name (the name of your previous step.