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
ClaireBear
Helper I
Helper I

Previous Month Calculated Column not working for January

Hello, 

 

I have a calculated column that flags previous month entries. The issue im having is that now in January, the calculation does not seem to work. Last year this was working beautifully. 

 

Example: 

IsPreviousMonth = IF (
YEAR ( 'Fact Sales'[TransactionDateTime].[Date]) = YEAR (TODAY ())
&& MONTH( 'Fact Sales'[TransactionDateTime].[Date]) = MONTH(TODAY () -30 ),
"Yes",
"No"
)
 
Secondly, i am trying to apply the same method to a quarter but have no luck. If previous quarter then"Yes" else "No"
Reason for all this - I am trying to create cards next to the graphs.
 
 
 

Example of CardsExample of Cards

 
 
 
 
 
 
 
 
 
 
Any suggestions would be great!
1 ACCEPTED SOLUTION

The Quarter function came with the 2019 december update.

You could use Roundup instead

 

IsPreviousQuarter = 

IF (
 YEAR ('Fact Sales'[TransactionDateTime].[Date]) & 
 ROUNDUP(MONTH('Fact Sales'[TransactionDateTime].[Date])/3,0) = 
  FORMAT(DATE( YEAR(TODAY()),
               ROUNDUP(MONTH(TODAY())/3,0)-1,
               DAY(TODAY())),"YYYYQ"),
"Yes",
"No"
)

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

If you have a date table you can use time intelligence functions

MTD (Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR('Date'[Date])))
MTD (Last Year End) Sales =  CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFYEAR(dateadd('Date'[Date],-12,MONTH),"8/31")))
Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,MONTH)) 
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date Filer],MAX(Sales[Sales Date]),-12,MONTH))  
3 month back MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-3,MONTH)))
 


QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(('Date'[Date])))

Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))
Next QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],1,QUARTER)))

Last year same QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,Year)))



YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"3/31"))

Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
2 Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(sales,sales[date] <=maxx(date,date[date])))

Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))  
Rolling last 12 before 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd('Date'[Date],-12,MONTH)),-12,MONTH))  

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Gordonlilj
Solution Sage
Solution Sage

Hi,

 

I'm not sure if this is what you're after but you could try and change the code to something like below

IsPreviousMonth = 

IF (
 YEAR ('Fact Sales'[TransactionDateTime].[Date]) & 
 MONTH( 'Fact Sales'[TransactionDateTime].[Date]) = 
 FORMAT(DATE( YEAR(TODAY()),
              MONTH(TODAY())-1,DAY(
              TODAY())),"YYYYM"),
"Yes",
"No"
)

 

Yes, thank you. It is working. 

I now have to figure out how to do this for Quarters.

If its the previous quarter you're after then you could probably replace MONTH with QUARTER like below

 

 

IsPreviousQuarter = 

IF (
 YEAR ('Fact Sales'[TransactionDateTime].[Date]) & 
 QUARTER( 'Fact Sales'[TransactionDateTime].[Date]) = 
  FORMAT(DATE( YEAR(TODAY()),
               QUARTER(TODAY())-1,
               DAY(TODAY())),"YYYYQ"),
"Yes",
"No"
)

 

 

 

Thank you! Unfortunately there is no calculation for Quarter. 

The Quarter function came with the 2019 december update.

You could use Roundup instead

 

IsPreviousQuarter = 

IF (
 YEAR ('Fact Sales'[TransactionDateTime].[Date]) & 
 ROUNDUP(MONTH('Fact Sales'[TransactionDateTime].[Date])/3,0) = 
  FORMAT(DATE( YEAR(TODAY()),
               ROUNDUP(MONTH(TODAY())/3,0)-1,
               DAY(TODAY())),"YYYYQ"),
"Yes",
"No"
)

Thank you so much! You have solved my issue. 

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.