The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Solved! Go to Solution.
= #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"}))
Beuaitful! Thank you so much! Clear 🙂
= #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"}))
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.