Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
alecw0444
New Member

Custom Column Query Help

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

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

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

alecw0444
New Member

bump

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.