Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
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
Check out the October 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
115 | |
112 | |
105 | |
95 | |
58 |
User | Count |
---|---|
174 | |
147 | |
136 | |
102 | |
82 |