Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Tlotly
Resolver II
Resolver II

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

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Tlotly ,

 

Create a column as below:

 

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

vkellymsft_0-1626150755957.png

For my sample .pbix file ,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

View solution in original post

6 REPLIES 6
v-kelly-msft
Community Support
Community Support

Hi @Tlotly ,

 

Create a column as below:

 

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

vkellymsft_0-1626150755957.png

For my sample .pbix file ,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

watkinnc
Super User
Super User

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


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!
watkinnc
Super User
Super User

Try this:

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

 


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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

 

Tlotly_0-1626076666096.png

 

mahoneypat
Employee
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

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors