Quantcast
Channel: Active questions tagged row - Stack Overflow
Viewing all articles
Browse latest Browse all 447

Power BI DAX: sum different columns based on row value

$
0
0

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:

CatAmountFringe
Salary50050
Salary60060
Other1000
Other1500

Desired matrix visual:

Cat**Value **
Fringe110
Salary1100
Other250

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 **
Salary1100
Other250

Viewing all articles
Browse latest Browse all 447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>