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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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

Top Solution Authors
Top Kudoed Authors