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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Anonymous
Not applicable

Can you set values based on the column name and the current year

I have a few columns with budgets for each year. The column names contain the years. 

I want to make a column that copies the values from the column name that contains the current year.                       

Like this:                                                              (2023) 
                                                                               V

Budget2022Budget2023Budget2024BudgetCurrentYear
1,000,000500,000700,000500,000
2,000,000400,000300,,000400,000
3,000,000600,000900,000600,000
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous,

 

This Power Query solution uses Unpivot Columns. I added an Account column--you'll likely have numerous dimension columns such as Company, Account, and Department.

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WMjQwUNJRMtQxMDAAYSDbFM4yh7JidaKVjMAiRkjqTOAsYyALrtAYIoSk0AzOsoQZGAsA", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Account = _t, Budget2022 = _t, Budget2023 = _t, Budget2024 = _t]
  ), 
  ChangeType = Table.TransformColumnTypes(
    Source, 
    {{"Budget2022", Int64.Type}, {"Budget2023", Int64.Type}, {"Budget2024", Int64.Type}}
  ), 
  UnpivotColumns = Table.UnpivotOtherColumns(ChangeType, {"Account"}, "Attribute", "Value"), 
  SplitColumn = Table.SplitColumn(
    UnpivotColumns, 
    "Attribute", 
    Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0" .. "9"}, c), {"0" .. "9"}), 
    {"Attribute.1", "Attribute.2"}
  ), 
  RemoveColumn = Table.RemoveColumns(SplitColumn, {"Attribute.1"}), 
  RenameColumn = Table.RenameColumns(RemoveColumn, {{"Attribute.2", "Year"}}), 
  ChangeType2 = Table.TransformColumnTypes(RenameColumn, {{"Year", Int64.Type}}), 
  AddIsCurrentYear = Table.AddColumn(
    ChangeType2, 
    "Is Current Year", 
    each if [Year] = Date.Year(DateTime.LocalNow()) then 1 else 0
  ), 
  ChangeType3 = Table.TransformColumnTypes(AddIsCurrentYear, {{"Is Current Year", Int64.Type}})
in
  ChangeType3

 

In your measures, you can add a condition for Is Current Year = 1.

 

DataInsights_0-1672930270551.png

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@Anonymous,

 

This Power Query solution uses Unpivot Columns. I added an Account column--you'll likely have numerous dimension columns such as Company, Account, and Department.

 

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText(
          "i45WMjQwUNJRMtQxMDAAYSDbFM4yh7JidaKVjMAiRkjqTOAsYyALrtAYIoSk0AzOsoQZGAsA", 
          BinaryEncoding.Base64
        ), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Account = _t, Budget2022 = _t, Budget2023 = _t, Budget2024 = _t]
  ), 
  ChangeType = Table.TransformColumnTypes(
    Source, 
    {{"Budget2022", Int64.Type}, {"Budget2023", Int64.Type}, {"Budget2024", Int64.Type}}
  ), 
  UnpivotColumns = Table.UnpivotOtherColumns(ChangeType, {"Account"}, "Attribute", "Value"), 
  SplitColumn = Table.SplitColumn(
    UnpivotColumns, 
    "Attribute", 
    Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0" .. "9"}, c), {"0" .. "9"}), 
    {"Attribute.1", "Attribute.2"}
  ), 
  RemoveColumn = Table.RemoveColumns(SplitColumn, {"Attribute.1"}), 
  RenameColumn = Table.RenameColumns(RemoveColumn, {{"Attribute.2", "Year"}}), 
  ChangeType2 = Table.TransformColumnTypes(RenameColumn, {{"Year", Int64.Type}}), 
  AddIsCurrentYear = Table.AddColumn(
    ChangeType2, 
    "Is Current Year", 
    each if [Year] = Date.Year(DateTime.LocalNow()) then 1 else 0
  ), 
  ChangeType3 = Table.TransformColumnTypes(AddIsCurrentYear, {{"Is Current Year", Int64.Type}})
in
  ChangeType3

 

In your measures, you can add a condition for Is Current Year = 1.

 

DataInsights_0-1672930270551.png

 





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

Proud to be a Super User!




Anonymous
Not applicable

Thank you this is amazing. I spend way to long trying to solve this myself.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.