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
manish-tripathi
Frequent Visitor

Adding Target Line for 2023 Cumulative Costs in Power BI Visual

Hello Power BI Community,

 

I am seeking assistance with a visual I've created to compare cumulative costs for the years 2022 and 2023.

 

For the visual, I have developed the following measure for cumulative costs:

 

```DAX
Cumulative Costs =
CALCULATE(
SUM('Cost 1'[Amount EUR]),
FILTER(
ALL('Calendar'[Date]), // Remove the filter context from the Calendar table
YEAR('Calendar'[Date]) = YEAR(MAX('Calendar'[Date])) &&
MONTH('Calendar'[Date]) <= MONTH(MAX('Cost 1'[Date]))
)
)
```

This measure is placed on the Y-axis, with the Calendar Month on the X-axis, and the Calendar Year as the legend.

My query is about incorporating a target line for 2023 cumulative costs into this visual. Currently, the use of the legend for differentiating between the years is preventing me from adding a secondary Y-axis. Is there a way to work around this issue? Should I create a separate measure to facilitate the addition of the target line?

I have attached a sample of the data and a screenshot of the visual for your reference.

Any guidance you can provide would be greatly appreciated.

 

Sample Visual and sample Dataset Attached:

https://drive.google.com/drive/folders/1IOviSSW_LKRWuyKH_R7Gh6RaDDj6_zZV?usp=sharing 

 

Best Regards,
Manish Tripathi

2 REPLIES 2
wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1698726749541.png

1 mark your calendar table as date table, and add a new column of YearMonth, then put it in the X axis

2022 Costs 1 = 
CALCULATE(
    SUM('Cost 1'[Amount EUR]),
    DATEADD(DATESYTD('Calendar'[Date]),-1,YEAR)
)

2023 Costs 1 = 
CALCULATE(
    SUM('Cost 1'[Amount EUR]),
    DATESYTD('Calendar'[Date]),YEAR('Calendar'[Date])=YEAR(TODAY())
)

TargetLine = CALCULATE(SUM('Cost 2'[Target]),DATESYTD('Calendar'[Date]),YEAR('Calendar'[Date])=YEAR(TODAY()))

 

Currently my metric has been further modified to interact with the year and month slicers on the Visualization page

Updated DAX Measure: ```LTM Costs Cumulative =
VAR MaxDate = MAX(Dates[Date])
VAR MinDate = EOMONTH(MaxDate, -12)

VAR Result =
IF(
HASONEVALUE('Previous Dates'[MonthYear]) &&
MAX('Previous Dates'[Date]) <= MaxDate &&
MIN('Previous Dates'[Date]) > MinDate,
CALCULATE(
[Cumulative Costs],
FILTER(
ALL(Dates),
Dates[Date].[Month] = VALUES('Previous Dates'[Date].[Month]) &&
Dates[Date].[Year] = VALUES('Previous Dates'[Date].[Year])
)
),
BLANK()
)

RETURN
Result``` where it uses the metric created earlier to SHOW Cumulative revenue for LTM, however the way you have suggested, it is not giving the desired output

I need something that is made available through the below link but for free
https://pbivizedit.com/gallery/line-chart

This allows multiple line charts

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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