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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.