Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Dear all,
Could you please support below issue:
I have a Power BI getting data from SAP BW. There is select month in parameter (Ex: 202011 for November 2020). I changed this one to a code base on the current date as below:
Currentmonth = Number.ToText(Date.Year(DateTime.Date(DateTime.LocalNow()))) & Number.ToText(Date.Month(DateTime.Date(DateTime.LocalNow())))
However, the result for month from Jan to Sep is only one character. It's not accepted as format of dataset. Could you please advise how can I adjust the code to return the value in 2 character.
Current result: 20201, 20202, 20203
Expected result: 202001, 202002, 202003,
Thanks much for your support!
Solved! Go to Solution.
Please try this change with Text.PadStart
= Number.ToText(Date.Year(DateTime.Date(DateTime.LocalNow()))) & Text.PadStart(Number.ToText(Date.Month(DateTime.Date(DateTime.LocalNow()))),2,"0")
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Please try this approach instead
= Date.ToText(Date.AddMonths(Date.From(DateTime.LocalNow()), -1), "yyyyMM")
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thanks so much!
Please try this change with Text.PadStart
= Number.ToText(Date.Year(DateTime.Date(DateTime.LocalNow()))) & Text.PadStart(Number.ToText(Date.Month(DateTime.Date(DateTime.LocalNow()))),2,"0")
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi Pat,
Thanks for your support.
Could you please advise if I want to create code for last month, how can I adjust this code?
As the previous one, I can minus to 1. But in this new one, it will revert the result is 202100.
let
#"LastMonth"= Number.ToText(Date.Year(DateTime.Date(DateTime.LocalNow()))) & Text.PadStart(Number.ToText(Date.Month(DateTime.Date(DateTime.LocalNow()))-1),2,"0")
in
#"LastMonth"
Thanks much!
Hello @Anonymous
you can use this formula for all your data needed (current month, last month, etc)
current month:
Date.ToText(Date.AddMonths(Date.From(DateTime.FixedLocalNow()),-0),"yyyyMM")
last month
Date.ToText(Date.AddMonths(Date.From(DateTime.FixedLocalNow()),-1),"yyyyMM")
etc
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!