I have two tables: A and B. A has one column [cat]. B has 3 columns: [cat], [amount], and [fringe]. A[cat] has 3 values: "Fringe", "Salary", and "Other". B[cat] only has 2 distinct values: "Salary" and "Other". There's a one to many relationship between A[cat] and B[cat].
I would like to have a matrix visual using A[cat] as the rows, and displaying values based on the row value. Specifically, when A[cat]="Fringe", the value is sum(B[Fringe]); when A[cat]<>'Fringe", the value is sum(B[Amount]).
Table A:
Cat |
---|
Fringe |
Salary |
Other |
Table B:
Cat | Amount | Fringe |
---|---|---|
Salary | 500 | 50 |
Salary | 600 | 60 |
Other | 100 | 0 |
Other | 150 | 0 |
Desired matrix visual:
Cat | **Value ** |
---|---|
Fringe | 110 |
Salary | 1100 |
Other | 250 |
I tried using the following DAX for a new measure, but the matrix rows only shows distinct values of B[cat], missing "Fringe".
DAX code of new measure:CALCULATE( SUMX( ALL(A[cat]), SWITCH( TRUE(), A[cat] = "Fringe", CALCULATE(SUM('B'[Fringe])), A[cat] <> "Fringe", CALCULATE(SUM('B'[Amount])) ) ))
matrix visual:
Cat | **Value ** |
---|---|
Salary | 1100 |
Other | 250 |