cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Helper I

Calculate variance between actual and target On or Before a target date

Hello community,

I am beginner in power bi, and I would like your help to figure out my problem.

I have two tables linked by id:

• the first table is the id, target date, and target value
• the second table is the id, actual date, and actual value

I want to calculate the variance between the target and actual according to the target date and actual date.

here is my table:

for example for id 1: I want to know the variance between the sum of actual values that happened on/before the target date:

So before 30-march I have the three orange values, so the result will sum(50,3000,2000)- 2000

My result will be:

Is there any way to implement this on power bi?

1 ACCEPTED SOLUTION
Community Support

Hi @unkCandy ,

First, create a measure:

``````variance =
VAR _a =
MAXX (
FILTER (
ALL ( 'target table' ),
[Id] = MAX ( 'target table'[Id] )
&& [target date] < MAX ( 'target table'[target date] )
),
[target date]
)
RETURN
CALCULATE (
SUM ( 'actual table'[actual] ),
FILTER (
'actual table',
[actual date] > _a
&& [actual date] <= MAX ( 'target table'[target date] )
)
)
- SUM ( 'target table'[target] )
``````

Then apply it to the table visual:

Final output:

Best Regards,

Jianbo Li

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

3 REPLIES 3
Community Support

Hi @unkCandy ,

How to get the target value based on the actual date? Can you please explain it in more detail? Is it based on the nearest target date to the actual date? Or is it before or after the actual date?

Best Regards,

Jianbo Li

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

Community Support

Hi @unkCandy ,

First, create a measure:

``````variance =
VAR _a =
MAXX (
FILTER (
ALL ( 'target table' ),
[Id] = MAX ( 'target table'[Id] )
&& [target date] < MAX ( 'target table'[target date] )
),
[target date]
)
RETURN
CALCULATE (
SUM ( 'actual table'[actual] ),
FILTER (
'actual table',
[actual date] > _a
&& [actual date] <= MAX ( 'target table'[target date] )
)
)
- SUM ( 'target table'[target] )
``````

Then apply it to the table visual:

Final output:

Best Regards,

Jianbo Li

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

Helper I

Hello,

I made a mistake explaining, I would like to calculate actual value -target value using target date.

I will explain, I want to extract the target value according to the actual date.

Here is an example:

My actual table is:

and my target table is as follows:

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:

I hope you can help,

thank you again.

Announcements

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors