Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
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:
Id | Actual date | Actual value |
1 | 31-Jan | 400 |
1 | 3-Mar | 500 |
1 | 18-May | 200 |
1 | 30-Sep | 300 |
1 | 15-Dec | 450 |
3 | 20-Feb | 3000 |
3 | 14-Jun | 4000 |
3 | 15-Aug | 500 |
3 | 5-Dec | 2000 |
and target table is as follow:
id | target date | target value |
1 | 31-Mar | 200 |
1 | 30-Aug | 100 |
3 | 31-Aug | 3000 |
3 | 30-Dec | 2000 |
I want to calculate actual- target values as the target can be retreived from the target table according to actual date. For example:
My result will look like as:
Id | Actual date | Actual value | Target value | Variance |
1 | 31-Jan | 400 | 200 | 200 |
1 | 3-Mar | 500 | 200 | 300 |
1 | 18-May | 200 | 200 | 0 |
1 | 30-Sep | 300 | 100 | 200 |
1 | 15-Dec | 450 | 100 | 150 |
3 | 20-Feb | 3000 | 3000 | 0 |
3 | 14-Jun | 4000 | 3000 | 1000 |
3 | 15-Aug | 500 | 3000 | -2500 |
3 | 5-Dec | 2000 | 2000 | 0 |
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.
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
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.
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
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.
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
User | Count |
---|---|
64 | |
59 | |
47 | |
33 | |
32 |
User | Count |
---|---|
84 | |
75 | |
56 | |
50 | |
44 |