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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
hcirak
Frequent Visitor

Dateadd Grand Total

Hello all,

 

I have a powerbi report below, that is very simple that consists of two columns: Quantity and Date. 

 

I have one relationship between Sales and Date, on Date column.

 

I want to calculate two measures. First, Sales Amount.

 

Sales Amount = SUM([Sales])
 
Second, I want to calculate a formula for previous month same period. I mean, when I select the first 13 days of February, it should calculate the formula for the first 13 days of January. My calculation is below:
 
Previous Month Same Period =
VAR LDS =
    LASTNONBLANK ( 'Date'[Date], Sales[Sales Amount] )
VAR CR =
    DATESBETWEEN ( 'Date'[Date], MIN ('Date'[Date] ), LDS)
VAR PR =
   DATEADD(CR,-1,MONTH )
RETURN
    IF (
      LDS >= MIN ( 'Date'[Date] ),
        CALCULATE ( Sales[Sales Amount] , PR )
    )
 
In this formula, row context is true but in grand total is false. 
 
hcirak_1-1676307655312.png

 

When I select the first 13 days of February, it gives me the wrong result in grand total. But if I select the first 12 days of February, it gives me correct grand total.

 

hcirak_2-1676307683453.png

 

 Could you please help me on that? 
 
Thanks in advance.
 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @hcirak 

please try

Previous Month Same Period =
SUMX (
VALUES ( 'Date'[Date] ),
CALCULATE (
VAR LDS =
LASTNONBLANK ( 'Date'[Date], Sales[Sales Amount] )
VAR CR =
DATESBETWEEN ( 'Date'[Date], MIN ( 'Date'[Date] ), LDS )
VAR PR =
DATEADD ( CR, -1, MONTH )
RETURN
IF ( LDS >= MIN ( 'Date'[Date] ), CALCULATE ( Sales[Sales Amount], PR ) )
)
)

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @hcirak 

please try

Previous Month Same Period =
SUMX (
VALUES ( 'Date'[Date] ),
CALCULATE (
VAR LDS =
LASTNONBLANK ( 'Date'[Date], Sales[Sales Amount] )
VAR CR =
DATESBETWEEN ( 'Date'[Date], MIN ( 'Date'[Date] ), LDS )
VAR PR =
DATEADD ( CR, -1, MONTH )
RETURN
IF ( LDS >= MIN ( 'Date'[Date] ), CALCULATE ( Sales[Sales Amount], PR ) )
)
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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