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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bensiqc
Helper I
Helper I

Create Calculated Column for Relative Month

I'm having trouble building out a calculated column that essentially uses a nested if statement to determine whether a period is within the current complete month (last month), the previous complete month (two months ago), or anything else ("Other").

 

Relative Complete Month = 
if(and(BillingSummary_0000_V70[Accounting Period Month Number] = MONTH(today()-1),BillingSummary_0000_V70[Accounting Period Year] = YEAR(today())),"Current Complete Month",if(and(BillingSummary_0000_V70[Accounting Period Month Number] = MONTH(today()-2),BillingSummary_0000_V70[Accounting Period Year] = YEAR(today())),"Prior Complete Month","Other"))

When I use the above, everything appears under the month of May or "Other". I'd expect data for the "Current Complete Month" to be April and "Prior Complete Month" to be March.

 

FYI, I have an accounting period column in the data which is just a date. Accounting Period Year is a number, Accounting Period Month Number is also a number.

 

I have some limitations with being able to link to any other data sources. I realize a date table would simplify this but I don't think it should be necessary. Just not sure why I can't get this formula working.

 

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

pls try this

 

Relative Complete Month = 
   VAR _toDay = TODAY()
   VAR _Last1month =  EOMONTH(_toDay,-1)
   VAR _Last2month =  EOMONTH(_toDay,-2)
RETURN
SWITCH( TRUE(),
      EOMONTH (BillingSummary_0000_V70[Accounting Period Date],0) = _Last1month , "Current Complete Month",
   
      EOMONTH (BillingSummary_0000_V70[Accounting Period Date],0) = _Last2month , "Prior Complete Month",

"Other" )

 

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

pls try this

 

Relative Complete Month = 
   VAR _toDay = TODAY()
   VAR _Last1month =  EOMONTH(_toDay,-1)
   VAR _Last2month =  EOMONTH(_toDay,-2)
RETURN
SWITCH( TRUE(),
      EOMONTH (BillingSummary_0000_V70[Accounting Period Date],0) = _Last1month , "Current Complete Month",
   
      EOMONTH (BillingSummary_0000_V70[Accounting Period Date],0) = _Last2month , "Prior Complete Month",

"Other" )

 

Exactly what I needed! Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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