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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
ValeriaBreve
Post Patron
Post Patron

Help to improve the creation of a table

Hello,

I have created a table with the below code.

It does work as expected, however I am sure I could have done it in a different way, more efficient, probably using lists as I am repeating practically the same thing for many rows, just changing the integers. But I can't figure out how...

 

Could you please help me to understand how this could be modified?

 

Thanks!

Kind regards

Valeria

 

 

let

versions = #table(
type table [Version = Text.Type, Version Text = Text.Type],

{

{"n", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-1),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),0),"MMMM") & " forecast"},
{"n - 1", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-2),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-1),"MMMM") & " forecast"},
{"n - 2", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-3),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-2),"MMMM") & " forecast"},
{"n - 3", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-4),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-3),"MMMM") & " forecast"},
{"n - 4", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-5),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-4),"MMMM") & " forecast"},
{"n - 5", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-6),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-5),"MMMM") & " forecast"},
{"n - 6", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-7),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-6),"MMMM") & " forecast"},
{"n - 7", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-8),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-7),"MMMM") & " forecast"},
{"n - 8", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-9),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-8),"MMMM") & " forecast"},
{"n - 9", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-10),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-9),"MMMM") & " forecast"},
{"n - 10", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-11),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-10),"MMMM") & " forecast"},
{"n - 11", Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-12),"MMMM") & " actuals / " & Date.ToText(Date.AddMonths(#date(Date.Year(DateTime.LocalNow()),Date.Month(DateTime.LocalNow()),5),-11),"MMMM") & " forecast"}
}
)


in
versions

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

= #table(type table [Version = Text.Type, Version Text = Text.Type],List.Transform({0..11},each {"n"&Number.ToText(_," - 0;;\"),DateTime.ToText(Date.AddMonths(DateTime.LocalNow(),-_-1),"MMMM")&" actuals / "&DateTime.ToText(Date.AddMonths(DateTime.LocalNow(),-_),"MMMM")&" forecast"}))

View solution in original post

2 REPLIES 2
ValeriaBreve
Post Patron
Post Patron

Beuaitful! Thank you so much! Clear 🙂

wdx223_Daniel
Super User
Super User

= #table(type table [Version = Text.Type, Version Text = Text.Type],List.Transform({0..11},each {"n"&Number.ToText(_," - 0;;\"),DateTime.ToText(Date.AddMonths(DateTime.LocalNow(),-_-1),"MMMM")&" actuals / "&DateTime.ToText(Date.AddMonths(DateTime.LocalNow(),-_),"MMMM")&" forecast"}))

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors