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
Leo64
New Member

Year interval

Hello,

 

I have 3 year intervals:

 

2020 - 2024

2025 - 2029

2030 - 2034

 

I would like to transform it to:

2020

2021

2022

2023

2024

2025 

etc. until 2034

 

How can I accomplish this?

 

Thank you in advance.

 

Leo

 

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

Hi @Leo64 ,

 

If you want to implement it in Power Query Editor, please refer to the following command.

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText("i45WMjIwMtAFEiZKsTpgnimIZwnlGYPkjIFysQA=", BinaryEncoding.Base64), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Year = _t]
  ), 
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"Year", type text}}), 
  #"Inserted Text Before Delimiter" = Table.AddColumn(
    #"Changed Type", 
    "Text Before Delimiter", 
    each Text.BeforeDelimiter([Year], "-"), 
    type text
  ), 
  #"Inserted Text After Delimiter" = Table.AddColumn(
    #"Inserted Text Before Delimiter", 
    "Text After Delimiter", 
    each Text.AfterDelimiter([Year], "-"), 
    type text
  ), 
  #"Renamed Columns" = Table.RenameColumns(
    #"Inserted Text After Delimiter", 
    {{"Text Before Delimiter", "StartYear"}, {"Text After Delimiter", "EndYear"}}
  ), 
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Renamed Columns", 
    {{"StartYear", Int64.Type}, {"EndYear", Int64.Type}}
  ), 
  #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each [EndYear] - [StartYear]), 
  #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom", {{"Custom", Int64.Type}}), 
  #"Added Custom1" = Table.AddColumn(
    #"Changed Type2", 
    "Custom.1", 
    each List.Numbers([StartYear], [Custom] + 1, 1)
  ), 
  #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"), 
  #"Removed Columns" = Table.RemoveColumns(
    #"Expanded Custom.1", 
    {"Year", "StartYear", "EndYear", "Custom"}
  )
in
  #"Removed Columns"

Attached PBIX file for reference, you can observe each step in APPLIED STEPS on the right.

vcgaomsft_0-1652950880642.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

Hi @Leo64 ,

 

If you want to implement it in Power Query Editor, please refer to the following command.

let
  Source = Table.FromRows(
    Json.Document(
      Binary.Decompress(
        Binary.FromText("i45WMjIwMtAFEiZKsTpgnimIZwnlGYPkjIFysQA=", BinaryEncoding.Base64), 
        Compression.Deflate
      )
    ), 
    let
      _t = ((type nullable text) meta [Serialized.Text = true])
    in
      type table [Year = _t]
  ), 
  #"Changed Type" = Table.TransformColumnTypes(Source, {{"Year", type text}}), 
  #"Inserted Text Before Delimiter" = Table.AddColumn(
    #"Changed Type", 
    "Text Before Delimiter", 
    each Text.BeforeDelimiter([Year], "-"), 
    type text
  ), 
  #"Inserted Text After Delimiter" = Table.AddColumn(
    #"Inserted Text Before Delimiter", 
    "Text After Delimiter", 
    each Text.AfterDelimiter([Year], "-"), 
    type text
  ), 
  #"Renamed Columns" = Table.RenameColumns(
    #"Inserted Text After Delimiter", 
    {{"Text Before Delimiter", "StartYear"}, {"Text After Delimiter", "EndYear"}}
  ), 
  #"Changed Type1" = Table.TransformColumnTypes(
    #"Renamed Columns", 
    {{"StartYear", Int64.Type}, {"EndYear", Int64.Type}}
  ), 
  #"Added Custom" = Table.AddColumn(#"Changed Type1", "Custom", each [EndYear] - [StartYear]), 
  #"Changed Type2" = Table.TransformColumnTypes(#"Added Custom", {{"Custom", Int64.Type}}), 
  #"Added Custom1" = Table.AddColumn(
    #"Changed Type2", 
    "Custom.1", 
    each List.Numbers([StartYear], [Custom] + 1, 1)
  ), 
  #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"), 
  #"Removed Columns" = Table.RemoveColumns(
    #"Expanded Custom.1", 
    {"Year", "StartYear", "EndYear", "Custom"}
  )
in
  #"Removed Columns"

Attached PBIX file for reference, you can observe each step in APPLIED STEPS on the right.

vcgaomsft_0-1652950880642.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

speedramps
Super User
Super User

You seem to have rushed this description.  😀

You will get a quicker resposne if you take time to include propoer input data examples. Thank you  😀

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.