Forum Discussion

bluetronics's avatar
bluetronics
Icon for Helper III rankHelper III
7 years ago
Solved

Compare Plan and actual data

Hello All,

 

I want to see the differences between Plan and Actual. I got the 2 tables form excel below. How do I make a table what I would like to see below?

 

 

 

Thanks in advance.

 

  • Hi bluetronics

     

    Although I believe it would be more convenient to do this in the query editor (M), you can also try creating a new calculated table with DAX:

     

    TestTable =
    VAR _BaseTable =
        DISTINCT (
            UNION (
                SUMMARIZECOLUMNS ( Actual[Customer]; Actual[Product] );
                SUMMARIZECOLUMNS ( Plan[Customer]; Plan[Product] )
            )
        )
    RETURN
        ADDCOLUMNS (
            _BaseTable;
            "Difference"; LOOKUPVALUE (
                Actual[Qty];
                Actual[Customer]; [Customer];
                Actual[Product]; [Product]
            )
                - LOOKUPVALUE ( Plan[Qty]; Plan[Customer]; [Customer]; Plan[Product]; [Product] )
        )

     

    Code formatted with  

  • HI @ AIB,

    Your instruction was great to work in general but I got an issue with "A table of multiple values was supplied where a single value was expected."  when I apply to big data. And I found it why but I don't know how to clear the issue. Can you help me agin?

    I can see the error message when there are differnt lookupvalue. Do you happen to know how to do if I want to sum of Qty for the same customer and product.

     

    Regards,

     

  • AlB's avatar
    AlB
    7 years ago

    bluetronics

     

    NewTable = 
    VAR _BaseTable =
        DISTINCT (
            UNION (
                SUMMARIZECOLUMNS ( Actual[Customer]; Actual[Product] );
                SUMMARIZECOLUMNS ( Plan[Customer]; Plan[Product] )
            )
        )
    RETURN
        ADDCOLUMNS (
            _BaseTable;
            "Difference"; 
            VAR _CurrentCustomer=[Customer]
            VAR _CurrentProduct=[Product] 
            RETURN 
               CALCULATE(SUM(Actual[Qty]); Actual[Customer]=_CurrentCustomer; Actual[Product]=_CurrentProduct)
               - CALCULATE(SUM(Plan[Qty]); Plan[Customer]=_CurrentCustomer; Plan[Product]=_CurrentProduct)
        )
  • bluetronics

    Or actually we could have another version with two nested ADDCOLUMNS to make the code a bit less verbose and avoid some recalculations which I'm guessing would be faster although I cannot be positive about it

     

    NewTableExtended_v2 = 
    VAR _BaseTable =
        DISTINCT (
            UNION (
                SUMMARIZECOLUMNS ( Actual[Customer]; Actual[Product] );
                SUMMARIZECOLUMNS ( Plan[Customer]; Plan[Product] )
            )
        )
    RETURN
        ADDCOLUMNS (
            ADDCOLUMNS (
                _BaseTable;
                "Plan-Qty";
                VAR _CurrentCustomer = [Customer]
                VAR _CurrentProduct = [Product]
                VAR _CurrentPlan =
                    CALCULATE (
                        SUM ( Plan[Qty] );
                        Plan[Customer] = _CurrentCustomer;
                        Plan[Product] = _CurrentProduct
                    )
                RETURN
                    _CurrentPlan;
                "Actual-Qty";
                VAR _CurrentCustomer = [Customer]
                VAR _CurrentProduct = [Product]
                VAR _CurrentActual =
                    CALCULATE (
                        SUM ( Actual[Qty] );
                        Actual[Customer] = _CurrentCustomer;
                        Actual[Product] = _CurrentProduct
                    )
                RETURN
                    _CurrentActual
            );
            "Diff. Qty"; [Actual-Qty] - [Plan-Qty]
        )

    Code formatted with  

13 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    Hi bluetronics

     

    Although I believe it would be more convenient to do this in the query editor (M), you can also try creating a new calculated table with DAX:

     

    TestTable =
    VAR _BaseTable =
        DISTINCT (
            UNION (
                SUMMARIZECOLUMNS ( Actual[Customer]; Actual[Product] );
                SUMMARIZECOLUMNS ( Plan[Customer]; Plan[Product] )
            )
        )
    RETURN
        ADDCOLUMNS (
            _BaseTable;
            "Difference"; LOOKUPVALUE (
                Actual[Qty];
                Actual[Customer]; [Customer];
                Actual[Product]; [Product]
            )
                - LOOKUPVALUE ( Plan[Qty]; Plan[Customer]; [Customer]; Plan[Product]; [Product] )
        )

     

    Code formatted with  

    • bluetronics's avatar
      bluetronics
      Icon for Helper III rankHelper III

      HI @AIB,

      Thanks a lot! it works excactly what I would like to see.

      Best Regards,

      SH Lee

    • bluetronics's avatar
      bluetronics
      Icon for Helper III rankHelper III

      HI @ AIB,

      Your instruction was great to work in general but I got an issue with "A table of multiple values was supplied where a single value was expected."  when I apply to big data. And I found it why but I don't know how to clear the issue. Can you help me agin?

      I can see the error message when there are differnt lookupvalue. Do you happen to know how to do if I want to sum of Qty for the same customer and product.

       

      Regards,

       

      • AlB's avatar
        AlB
        Icon for Community Champion rankCommunity Champion

        bluetronics

         

        NewTable = 
        VAR _BaseTable =
            DISTINCT (
                UNION (
                    SUMMARIZECOLUMNS ( Actual[Customer]; Actual[Product] );
                    SUMMARIZECOLUMNS ( Plan[Customer]; Plan[Product] )
                )
            )
        RETURN
            ADDCOLUMNS (
                _BaseTable;
                "Difference"; 
                VAR _CurrentCustomer=[Customer]
                VAR _CurrentProduct=[Product] 
                RETURN 
                   CALCULATE(SUM(Actual[Qty]); Actual[Customer]=_CurrentCustomer; Actual[Product]=_CurrentProduct)
                   - CALCULATE(SUM(Plan[Qty]); Plan[Customer]=_CurrentCustomer; Plan[Product]=_CurrentProduct)
            )