Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello,
I am trying to get the following code to work but it will not work in Power BI. For reference, I am trying to develop a bar chart that will show a 6 month history of results. Every month has its own file (all are named ThatMonth_Info.... i.e. 'February_Info', 'March_Info', etc). I am trying to make this completely automated, so years down the line it can auto-update the chart.
This is the reason for the Date.Month(DateTime.FixedLocalNow()) = 1-6 you see below. If we are in the first six months, I want the data heading to update with the previous year (2018), but if we are in the latter six months, I want the data heading to update with the current year.
Currently with the below formula, all my data is populating as 'Jul 2018' (in blue text below)- it's like Power BI is not reading the 'AND' I have (in red below).
Any ideas where I am going wrong?
if Date.Month(DateTime.FixedLocalNow()) = 1 or Date.Month(DateTime.FixedLocalNow()) = 2 or Date.Month(DateTime.FixedLocalNow()) = 3 or Date.Month(DateTime.FixedLocalNow()) = 4 or Date.Month(DateTime.FixedLocalNow()) = 5 or Date.Month(DateTime.FixedLocalNow()) = 6 and Text.Contains([Source.Name], "July") then "Jul " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "August") then "Aug " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "September") then "Sep " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "October") then "Oct " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "November") then "Nov " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "December") then "Dec " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),-1))) else if Text.Contains([Source.Name], "January") then "Jan " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "February") then "Feb " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "March") then "Mar " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "April") then "Apr " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "May") then "May " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "June") then "Jun " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "July") then "Jul " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "August") then "Aug " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "September") then "Sep " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "October") then "Oct " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "November") then "Nov " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else if Text.Contains([Source.Name], "December") then "Dec " & Text.From(Date.Year(Date.AddYears(DateTime.FixedLocalNow(),0))) else null
Hi @alecw0444
As you said,"Every month has its own file", it means there are many tables with month and details, right?
If so, you need merge or append these tables first.
Then to do a 6 month history of results, it may be easy to do with DAX in Power BI.
Additionally,
This article contains numerous suggestions and recommendations that will help you get your particular question about Power BI answered quickly and correctly versus seemingly ignored.
Best Regards
Maggie
bump