0
votes

I want to create a report in power Bi that shows the turnover for each year but in my database a turnover can not be equal to the total amount of the bills because there can be assets to be deducted. so in my database there is operation_code table which contains a SENS column this column indicates if this operation is either input or output and the turnover will be calculated as follows: if (CODE_OP.SENS = output), + sum (ENT.HTMT / ENT .DEVP) else if (CODE_OP.SENS = input), - sum (ENT.HTMT / ENT.DEVP) i did a test with SQL Statements :

SELECT YEAR(ENT.PIDT) ,T020.SENS,
CASE 
     WHEN T020.SENS= 2 THEN 
      sum (ENT.HTMT / ENT.DEVP) 
      WHEN T020.SENS = 1 THEN -1 * sum (ENT.HTMT / ENT.DEVP) 
    END as CA FROM ENT
left join T020  on 
    T020.OP = ENT.OP 
WHERE ENT.PICOD=4 AND ENT.TICOD='C'  AND ENT.DOS=998
GROUP BY YEAR(ENT.PIDT)--,T020.SENS

but when i try to do it in power BI Using DAX by creating a measure

Measure = 

Switch ( True();

 ALL(T020[SENS])=2,0;SUM(ENT[HTMT])/SUM(ENT[DEVP]) ;

 ALL(T020[SENS])=1,0; SUM(ENT[HTMT])/(SUM(ENT[DEVP])) 
 ) 

an error appear when i try to use the measure that it is impossible to display the visual element . enter image description here

1
Welcome to SO. Can you please post a small data example (not necessarily real data) with expected output?user5226582

1 Answers

0
votes

The following DAX should do the trick:

Measure = 
CALCULATE(
    SUMX(ENT, DIVIDE(ENT[HTMT], ENT[DEVP])),
    T020[SENS] = 2
) 
- CALCULATE(
    SUMX(ENT, DIVIDE(ENT[HTMT], ENT[DEVP])),
    T020[SENS] = 1
)