Forum Discussion

Z7-852's avatar
Z7-852
Helper I
10 years ago

DAX: Calculating sum over relative table

I having troubles forming a calculations over relative table.

 

My data is in three tables (A, B and C). In C table there are rows that contain A.ID and B.ID and a number (#). 

Tables A and B have no logical relationship.

I need a table with following cross join.

 

A.IDB.ID#
11SUM #
12SUM #
21SUM #
22SUM #

 

And so on.
Guestion that I'am trying to ask is "How much item B is used by item A?" and "Is usage of item B by item A more or less than avarage between all the As?"

 

If I try to use CrossJoin it gives me memory error because the cross join table is too large. I figured I have to use measure that calculates the SUM but I haven't figured out how to do it over two tables.

6 Replies

  • I solved this by using SQL but I would still like to know how to do this in DAX.

     

    Solution was something like


    SELECT C.AId, C.BId, SUM(number) OVER (PARTITION BY AId)
    FROM C

    WHERE AId IS NOT NULL AND BId IS NOT NULL
    GROUP BY AId, BId

    • MattAllington's avatar
      MattAllington
      Community Champion

      It's a bit hard to understand what you want. How about you build a small sample workbook, make the joins and show the output you are after

      • Z7-852's avatar
        Z7-852
        Helper I

        Table A

        ID
        1
        2
        3
        4
        5

         

        Table B

        ID
        1
        2
        3
        4
        5

         

        Table C (Consumption number of B by user A. Also contains data like date)

        Almost all the information needed is in table C.

        AIDBIDNUMBER
        1110
        3120
        3230
        4140
        3250

         

        Result

        AIDBIDSUM(number)
        1110
        3120
        3280
        4140

         

        The SQL code that I posted worked and I was also able to use SQL to calculate other totals like (B1 usage in this example 70 and total A3 usage in this example 100).

         

        Problem with SQL code that I used was that it removed time dimension from data because of the GROUP BY clause.
        It would be nice if I had one measure that would tell me "Does this A consume more B than avarage A?"