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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
mellania
New Member

Calculate Actual vs Target that has specific dates

Hello, 

I am getting started with power bi and I have an issue with calculating the variance between actual values and target values. 

I have two table actual and target table. 

the actual table is as follow: 

IdActual dateActual value
131-Jan400
13-Mar500
118-May200
130-Sep300
115-Dec450
320-Feb3000
314-Jun4000
315-Aug500
35-Dec2000

and target table is as follow: 

idtarget datetarget value
131-Mar200
130-Aug100
331-Aug3000
330-Dec2000

I want to calculate actual- target values as the target can be retreived from the target table according to actual date. For example:

  • For id=1, first row I have the date 31-Jan so I should the target value of the date 31-march
  • for id=1, forth row, i have the date 30-Sep so i should get the target value of the date 30-Aug 

My result will look like as: 

IdActual dateActual valueTarget valueVariance
131-Jan400200200
13-Mar500200300
118-May2002000
130-Sep300100200
115-Dec450100150
320-Feb300030000
314-Jun400030001000
315-Aug5003000-2500
35-Dec200020000

I want to implement it in dax but i dont know how to retrieve the target value according to actual date. 

I hope you can help me to do that, 

thanks.

5 REPLIES 5
Anonymous
Not applicable

Hi @mellania,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Ashish_Mathur
Super User
Super User

Hi,

These calculated column formulas work in the Actual table.

Next nearest target date=CALCULATE(MIN(Target[target date]),FILTER(Target,Target[id]=EARLIER(Actual[Id])&&Target[target date]>=EARLIER(Actual[Actual date])))
Past nearest target date=CALCULATE(max(Target[target date]),FILTER(Target,Target[id]=EARLIER(Actual[Id])&&Target[target date]<=EARLIER(Actual[Actual date])))
Target date to be considered=if(ISBLANK(Actual[Past nearest target date]),Actual[Next nearest target date],if(ISBLANK(Actual[Next nearest target date]),Actual[Past nearest target date],if(abs(Actual[Actual date]-Actual[Next nearest target date])<abs(Actual[Actual date]-Actual[Past nearest target date]),[Next nearest target date],[Past nearest target date])))
Target value=LOOKUPVALUE(Target[target value],Target[id],Actual[Id],Target[target date],Actual[Target date to be considered])

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello sir, 

Thank you for your reply, I applied the calculation. but I want it if the actual date is passed the target date get the next target date. 

For example

  • I have three targets dates: 15-March, 30-June, 31-Dec.
  • I have three actuals dates: 30-April, 31-Aug, 31-Dec. 
    • So for the 30-April, I want to get the date 30-june. 
    • So for the 30-Aug I want to get 31-Dec 
    • And for the 31-Dec I want to 31-Dec. 

 

Is there any possible way to implement this? Here is my pbix where i did implement the calculation: https://drive.google.com/file/d/1mqsOnlm0Er1jqz6pYIrD9dApckloZvbi/view?usp=sharing

Thank you for your reply. 

You have just changed the question.  On the PBI file that you have shared, show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @mellania,

In fact, power bi data mode table does not contain row and column index so it not suitable or accurate extract the specific row/cell values. (You need to use filters to help Dax expression locate these fields values)
I'd like to suggest you add an index based on the id group in query editor side, then you can use Dax formula to use current index and id field values to find out corresponds value to calculate.

Create Row Number for Each Group in Power BI using Power Query - RADACAD

Regards,

Xiaoxin Sheng

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.