Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi, I was trying to come up with a DAX code to return me the last 12 months' sales from the max dashboard's slicer date. I came up with the following code:
mo_months_to_show =
Var MAX_DATE = MAX('Time'[Date])
Var PREVIOUS_DATES = DATESINPERIOD('calender_months_display'[Date],MAX_DATE,-12,MONTH)
Var RESULT = CALCULATE([Value - Net Sales],REMOVEFILTERS('Time'),KEEPFILTERS(PREVIOUS_DATES),USERELATIONSHIP('Time'[Date],calender_months_display[Date]))
Return RESULT
However, this code shows the line graph but trailing. I want to show the line side by side.
I have also tried another code:
CALCULATE([mo_months_to_show],SAMEPERIODLASTYEAR('Time'[Date]))
But I get the same graph result.
I want both lines overlapped.
Solved! Go to Solution.
Hi @topgun_ninja ,
Please try below steps, i create a sample for you:
1. below is my test table
Table:
Table 2:
create with below dax formula:
Table 2 =
ADDCOLUMNS (
CALENDAR ( FIRSTDATE ( 'Table'[Date] ), LASTDATE ( 'Table'[Date] ) ),
"YYYY-MMM",
FORMAT ( [Date], "mmm" ) & " "
& YEAR ( [Date] )
)
Model:
2. create measure with below dax formula
Current Year= SUM('Table'[Sale])Last Year =
VAR cur_ym =
SELECTEDVALUE ( 'Table 2'[YYYY-MMM] )
VAR cur_year =
INT ( RIGHT ( cur_ym, 4 ) )
VAR _month =
CALCULATE ( MONTH ( MAX ( 'Table 2'[Date] ) ), 'Table 2'[YYYY-MMM] = cur_ym )
RETURN
CALCULATE (
[Measure],
YEAR ( 'Table 2'[Date] ) = cur_year - 1
&& MONTH ( 'Table 2'[Date] ) = _month
)
3. add line chart with field and measure, and apply some filter
Please refer the attached .pbix file.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @topgun_ninja ,
Please try below steps, i create a sample for you:
1. below is my test table
Table:
Table 2:
create with below dax formula:
Table 2 =
ADDCOLUMNS (
CALENDAR ( FIRSTDATE ( 'Table'[Date] ), LASTDATE ( 'Table'[Date] ) ),
"YYYY-MMM",
FORMAT ( [Date], "mmm" ) & " "
& YEAR ( [Date] )
)
Model:
2. create measure with below dax formula
Current Year= SUM('Table'[Sale])Last Year =
VAR cur_ym =
SELECTEDVALUE ( 'Table 2'[YYYY-MMM] )
VAR cur_year =
INT ( RIGHT ( cur_ym, 4 ) )
VAR _month =
CALCULATE ( MONTH ( MAX ( 'Table 2'[Date] ) ), 'Table 2'[YYYY-MMM] = cur_ym )
RETURN
CALCULATE (
[Measure],
YEAR ( 'Table 2'[Date] ) = cur_year - 1
&& MONTH ( 'Table 2'[Date] ) = _month
)
3. add line chart with field and measure, and apply some filter
Please refer the attached .pbix file.
Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
can you give a expected result spanshot
This is my expected result snapshot:
Instead, I get this:
I have already tried this method. It doesn't work.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 39 | |
| 38 | |
| 38 | |
| 28 | |
| 27 |
| User | Count |
|---|---|
| 124 | |
| 88 | |
| 73 | |
| 66 | |
| 65 |