Forum Discussion
Dynamic Formula based on columns selection in report
Hi,
I have columns like below.
| Jan:Forecast | Jan:Actual | Feb:Forecast | Feb:Actual |
| $2,906,186 | $2,968,527 | 59813.447 | 66870 |
have created a report in power BI in Table Visualzations, in which I select these columns month wise like below
| Jan:Forecast | Jan:Actual |
| $2,906,186 | $2,968,527 |
I want 1 more column beside this as- " Variance". which will calculate difference between forecast and actuals, but based on which month I select.
Just wanted to know if there is any way we can have a Dynamic Variance Formula, based on which column i select in report.
Thanks in advance.
7 Replies
- v-yulgu-msftMicrosoft Employee
Hi Anonymous,
Please see below steps:
Unpivot table to convert table to below structure.
Duplicate column [Month:Category], then, split it by ":".
Save and apply all above changes. Return back to data view, create a calculated column:
Difference = CALCULATE ( SUM ( 'Month Data'[Value] ), FILTER ( ALLEXCEPT ( 'Month Data', 'Month Data'[Month] ), 'Month Data'[Forecast/Actual] = "Actual" ) ) - CALCULATE ( SUM ( 'Month Data'[Value] ), FILTER ( ALLEXCEPT ( 'Month Data', 'Month Data'[Month] ), 'Month Data'[Forecast/Actual] = "Forecast" ) )Based on above table, create a new calculated table:
Month Data2 = UNION ( SELECTCOLUMNS ( 'Month Data', "Month:Category", 'Month Data'[Month:Category], "Values", 'Month Data'[Value], "Month", 'Month Data'[Month], "Forecast/Actual", 'Month Data'[Forecast/Actual] ), SELECTCOLUMNS ( 'Month Data', "Month:Category", "Difference", "Values", 'Month Data'[Difference], "Month", 'Month Data'[Month], "Forecast/Actual", "Difference" ) )Insert a Matrix visual, drag corresponding fields from 'Month Data2' into it.
Best regards,
Yuliana Gu
- AnonymousNot applicable
Hi,
Thanks for the solution. But I am stuck. I followed all steps but not getting the right numbers in difference.
Probably because I have one more column of project ID's.
Project IDJan:Forecast - Cost AmtJan:Actuals - Cost AmtFeb:Forecast - Cost AmtFeb:Actuals - Cost AmtMar:Forecast - Cost AmtMar:Actuals - Cost Amt
31542 36250.88 0 33395.17 0 43031.21 0 31602 58775.24 0 48170.41 0 66959.33 0 40101 320918.4607 0 305591.4645 0 279818.4746 0 40183 228304.3085 0 226854.8628 0 266345.6155 0 40215 2987.9999 0 null null null null 40340 106325.3847 0 100815.1504 0 78004.8078 0 41374 24954.0007 0 22561.28963 0 27309.88065 0 43653 null null null null null null 43713 4408.099458 0 3486.638468 0 4013.245268 0 43787 36097.74232 0 35440.54849 0 35924.40978 0 44796 1184898.92 0 884738.6912 0 848639.6938 0 45137 56194.75198 0 55520.32244 0 51295.28978 0 45163 29332.92 0 27031.53 0 37155.89 0 45164 26852.48 0 25735.82 0 34689.66 0 45267 38644.67788 0 34929.30785 0 43650.24222 0 45561 22585.85013 0 20510.68238 0 19823.0985 0 46161 17938.81884 0 3833.697121 0 47971.04417 0 46173 316535.2076 0 266872.2876 0 218511.0533 0 46184 329184.219 0 259830.424 0 218923.2539 0 46186 48218.10139 0 20763.56972 0 28642.57797 0 46197 163235.4098 0 159484.3587 0 176650.8291 0 46304 48772.38784 0 45695.7153 0 43634.20609 0 46347 80323.08158 0 92107.20029 0 109481.9491 0 46389 null null null null null null 46427 null null null null null null 46607 2707.384866 0 3037.481118 0 2995.0762 0 46702 302055.3106 0 280555.2731 0 346851.0776 0 46713 21284.57275 0 12441.01346 0 16170.3822 0 47185 32887.44064 0 3276.475584 0 3460.987968 0 47193 241692.6218 0 229724.6302 0 289179.3589 0 47194 128972.4388 0 118934.3367 0 131606.8208 0 47195 161221.4855 0 156235.8408 0 154288.9323 0 47196 41453.00179 0 93030.71341 0 89046.17967 0 47197 181506.9536 0 189635.0546 0 177180.6782 0 47212 null null null null null null Above is the table I have. And I want to have difference between forecast and actuals for each project. and month wise.
Also in above table i already have calculated measures based on those columns. Will that measures be affected if Unpivot columns and do all other stuff.?
Please help to find the variance.
- v-yulgu-msftMicrosoft Employee
Hi Anonymous,
Could you please add column headers to above table? Which column represents Project ID?
Regards,
Yuliana Gu