Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Dynamic Formula based on columns selection in report

Hi,

 

I have columns like below.

 

Jan:ForecastJan:ActualFeb:ForecastFeb:Actual
$2,906,186$2,968,52759813.44766870


 have created a report in power BI in Table Visualzations, in which I select these  columns month wise like below

 

Jan:ForecastJan: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-msft's avatar
    v-yulgu-msft
    Microsoft 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

    • Anonymous's avatar
      Anonymous
      Not 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

      3154236250.88033395.17043031.210
      3160258775.24048170.41066959.330
      40101320918.46070305591.46450279818.47460
      40183228304.30850226854.86280266345.61550
      402152987.99990nullnullnullnull
      40340106325.38470100815.1504078004.80780
      4137424954.0007022561.28963027309.880650
      43653nullnullnullnullnullnull
      437134408.09945803486.63846804013.2452680
      4378736097.74232035440.54849035924.409780
      447961184898.920884738.69120848639.69380
      4513756194.75198055520.32244051295.289780
      4516329332.92027031.53037155.890
      4516426852.48025735.82034689.660
      4526738644.67788034929.30785043650.242220
      4556122585.85013020510.68238019823.09850
      4616117938.8188403833.697121047971.044170
      46173316535.20760266872.28760218511.05330
      46184329184.2190259830.4240218923.25390
      4618648218.10139020763.56972028642.577970
      46197163235.40980159484.35870176650.82910
      4630448772.38784045695.7153043634.206090
      4634780323.08158092107.200290109481.94910
      46389nullnullnullnullnullnull
      46427nullnullnullnullnullnull
      466072707.38486603037.48111802995.07620
      46702302055.31060280555.27310346851.07760
      4671321284.57275012441.01346016170.38220
      4718532887.4406403276.47558403460.9879680
      47193241692.62180229724.63020289179.35890
      47194128972.43880118934.33670131606.82080
      47195161221.48550156235.84080154288.93230
      4719641453.00179093030.71341089046.179670
      47197181506.95360189635.05460177180.67820
      47212nullnullnullnullnullnull

       

      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-msft's avatar
        v-yulgu-msft
        Microsoft Employee

        Hi Anonymous,

         

        Could you please add column headers to above table? Which column represents Project ID?

         

        Regards,

        Yuliana Gu