Hello @harishrathore,
Thank You for posting your query onto the Forum.
To achieve the results based on the condition that you’ve specified. You’ll be required to add one more Date table inside the data model and create an inactive relationship with the original Date table. Below is the screenshot of the data model provided for the reference -
Now, create a measure for the “Total Sales Last 3 Months” -
Total Sales Last 3 Months =
VAR _Reference_Date =
MAX( Dates[Date] )
VAR _Previous_Dates =
DATESINPERIOD(
'Previous Dates'[Date] ,
_Reference_Date ,
- 3 ,
MONTH )
VAR _Results =
CALCULATE(
SUMX( Sales ,
Sales[Order Quantity] * Sales[Unit Price] ) ,
REMOVEFILTERS( Dates ) ,
KEEPFILTERS( _Previous_Dates ) ,
USERELATIONSHIP( Dates[Date] , 'Previous Dates'[Date] ) )
RETURN
_Results
Since based on the same slicer selection, you also want to calculate “Total Sales for Previous Last 3 Months”. Create the measure as provided below -
Total Sales Previous Last 3 Months =
VAR _Reference_Date =
MAX( Dates[Date] )
VAR _Previous_Dates =
DATESINPERIOD(
'Previous Dates'[Date] ,
_Reference_Date ,
- 6 ,
MONTH )
VAR _Results =
CALCULATE(
CALCULATE(
SUMX( Sales ,
Sales[Order Quantity] * Sales[Unit Price] ) ,
REMOVEFILTERS( Dates ) ,
KEEPFILTERS( _Previous_Dates ) ,
USERELATIONSHIP( Dates[Date] , 'Previous Dates'[Date] ) ) ,
DATEADD('Previous Dates'[Date] , -3 , MONTH ) )
RETURN
IF( ISBLANK( [Total Sales Last 3 Months] ) ,
BLANK() ,
_Results )
And finally, to fix the totals of the “Total Sales for Previous Last 3 Months” create this small measure -
Total Sales Previous Last 3 Months - Totals =
SUMX(
SUMMARIZE(
'Previous Dates' ,
'Previous Dates'[Month & Year] ,
"@Totals" ,
[Total Sales Previous Last 3 Months] ) ,
[@Totals]
)
Below is the screenshot of the final results provided for the reference -
I’m also attaching the working of the PBIX file for the reference purposes.
Hoping you find this useful and meets your requirements that you’ve been looking for.
Thanks and Warm Regards,
Harsh
Last 3 Months Vs Previous Last 3 Months - Harsh.pbix (702.6 KB)