cancel
Showing results for 
Search instead for 
Did you mean: 
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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors