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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sumeetkr
New Member

Target Line

I have a table in which I have one column "Status" it is a string column containing 2 categorical values "Achieved" and "Not-Achieved" based on which I have calculated the count and percentage for both the categories. I want created a target line for upper and lower limit. I am displaying the data in month day wise format.
LOGIC: My logic for creating target line is that I want to check the top 3 values of each month here I have to consider 3 months for calculation. In the top 3 values of each month which is the lowest i.e the target line should cross atleast top 3 values of each month. And when new month is added it should take the new month data to calculate and not consider previous month.
FOR EXAMPLE: I have data from Aug to Dec and now Jan also I have started to add in it. To calculate the Target Line I will check the top 3 percentage in Aug, Sep, and Oct total 9 values and set the target line which will cross the 9 values in the chart. As now I have added Jan data the target line should consider Nov, Dec, and Jan values to set a new target.

Currently I have add target line manually:

sumeetkr_0-1736833677131.png

Sample data:

sumeetkr_1-1736833728324.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @sumeetkr ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.

vtangjiemsft_0-1737009713867.png

 

(2) We can create a measure. 

target = 
var _total=9
var _max_date=CALCULATE(MAX('Table'[Physical Vehicle Delivered Time]),ALLSELECTED('Table'))
var _max_date_1=DATE(YEAR(_max_date),MONTH(_max_date),1)
var _max_date_2=DATE(YEAR(EDATE(_max_date,-1)),MONTH(EDATE(_max_date,-1)),1)
var _max_date_3=DATE(YEAR(EDATE(_max_date,-2)),MONTH(EDATE(_max_date,-2)),1)
var _KPI_Yes1 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_1 && [Physical Vehicle Delivered Time]<=_max_date_1+2))
var _KPI_Yes2 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_2 && [Physical Vehicle Delivered Time]<=_max_date_2+2))
var _KPI_Yes3 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_3 && [Physical Vehicle Delivered Time]<=_max_date_3+2))
RETURN  (_KPI_Yes1+_KPI_Yes2+_KPI_Yes3)/_total

In my test table, January 2025 is the most recent data, so the calculations are for attainment from the 1st through the 3rd of each month for January 2025, December 2024, and November 2024, and based on your description of three months and three dates then the total is 9.

 

(3) Then the result is as follows.

vtangjiemsft_1-1737010064287.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @sumeetkr ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.

vtangjiemsft_0-1737009713867.png

 

(2) We can create a measure. 

target = 
var _total=9
var _max_date=CALCULATE(MAX('Table'[Physical Vehicle Delivered Time]),ALLSELECTED('Table'))
var _max_date_1=DATE(YEAR(_max_date),MONTH(_max_date),1)
var _max_date_2=DATE(YEAR(EDATE(_max_date,-1)),MONTH(EDATE(_max_date,-1)),1)
var _max_date_3=DATE(YEAR(EDATE(_max_date,-2)),MONTH(EDATE(_max_date,-2)),1)
var _KPI_Yes1 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_1 && [Physical Vehicle Delivered Time]<=_max_date_1+2))
var _KPI_Yes2 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_2 && [Physical Vehicle Delivered Time]<=_max_date_2+2))
var _KPI_Yes3 = COUNTROWS(FILTER(ALLSELECTED('Table'),[KPI Status]="Achieved"&& [Physical Vehicle Delivered Time]>=_max_date_3 && [Physical Vehicle Delivered Time]<=_max_date_3+2))
RETURN  (_KPI_Yes1+_KPI_Yes2+_KPI_Yes3)/_total

In my test table, January 2025 is the most recent data, so the calculations are for attainment from the 1st through the 3rd of each month for January 2025, December 2024, and November 2024, and based on your description of three months and three dates then the total is 9.

 

(3) Then the result is as follows.

vtangjiemsft_1-1737010064287.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

danextian
Super User
Super User

Hi @sumeetkr 

 

If you're sharing a sample, please ensure it's in a usable format (not an image). You can post a link to a sanitized copy of your .pbix or Excel file. Make sure the sample data is complete. Explain how to utilize the sample data—how does the second screenshot connect to the percentages in the first? Demonstrate your expected result using the same sample data and provide the reasoning behind it.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I have used KPI_Status column to calculate the count and percentage of "Achieved".

Count formula: 

KPI_Yes = CALCULATE(COUNT(DUMP[Status]),DUMP[Status] = "Achieved")
Percentage formula:
Achieved% = [KPI_Yes]/[Total]
KPI_Status is defined by "TAT wrt FRM" if it is less than 0 then "not-achieved" else "achieved". I have plotted the graph based on "Physical Vehicle Delivered Time" month and day in x-axis and percentage in y-axis. Now I want to plot dynamic target line so that when any filter is applied the target line changes according to it.
 
Below is the Sample Table:
ShortDicv Regional OfficePre Order DatePhysical Vehicle Delivered TimeSTD FRMFRM+3HTATTAT wrt FRMKPI StatusMonth
ABUTANIEAST109-09-2024 09:2108-10-2024 12:0314.017.0698.7-681.7Not AchievedOct'24
ABUTANIEAST125-09-2024 10:1703-10-2024 18:1619.122.1200.0-177.9Not AchievedOct'24
ABUTANIEAST127-09-2024 09:5301-10-2024 18:3319.922.9104.7-81.8Not AchievedOct'24
ABUTANIEAST130-09-2024 09:4101-10-2024 15:481.84.830.1-25.3Not AchievedOct'24
ABUTANIEAST101-10-2024 09:3903-10-2024 09:139.312.347.6-35.3Not AchievedOct'24
ABUTANIEAST130-09-2024 10:2907-10-2024 11:571.04.0169.5-165.5Not AchievedOct'24
ABUTANIEAST101-10-2024 09:4001-10-2024 12:230.53.52.70.8AchievedOct'24
ABUTANIEAST101-10-2024 09:3603-10-2024 20:292.25.258.9-53.7Not AchievedOct'24
ABUTANIEAST101-10-2024 13:0301-10-2024 17:526.59.54.84.7AchievedOct'24
ABUTANIEAST101-10-2024 11:4001-10-2024 17:131.04.05.6-1.6Not AchievedOct'24
ABUTANIEAST101-10-2024 13:0701-10-2024 18:370.03.05.5-2.5Not AchievedOct'24
ABUTANIEAST101-10-2024 17:5901-10-2024 18:080.03.00.22.8AchievedOct'24
ABUTANIEAST103-10-2024 09:4003-10-2024 12:540.73.73.20.5AchievedOct'24
ABUTANIEAST101-10-2024 15:1605-10-2024 12:377.110.193.4-83.3Not AchievedOct'24
ABUTANIEAST103-10-2024 09:3703-10-2024 18:220.23.28.8-5.6Not AchievedOct'24
ABUTANIEAST103-10-2024 09:5603-10-2024 17:121.64.67.3-2.7Not AchievedOct'24
TOPSELEAST101-10-2024 09:5301-10-2024 16:364.07.06.70.3AchievedOct'24
TOPSELEAST101-10-2024 09:0701-10-2024 14:545.58.55.82.7AchievedOct'24
TOPSELEAST101-10-2024 09:0501-10-2024 18:2015.018.09.28.8AchievedOct'24
TOPSELEAST101-10-2024 10:1601-10-2024 18:0414.317.37.89.5AchievedOct'24
TOPSELEAST101-10-2024 08:4201-10-2024 16:501.64.68.1-3.5Not AchievedOct'24

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.