Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 ENTleft 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; -1 *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 .
Solved! Go to Solution.
Hi @Anonymous,
You can try to use below measure to calculate with switch function.
Measure = SWITCH ( SELECTEDVALUE ( T020[SENS] ); 2; SUM ( ENT[HTMT] ) / SUM ( ENT[DEVP] ); 1; -1 * SUM ( ENT[HTMT] ) / ( SUM ( ENT[DEVP] ) ); BLANK () )
Notice: switch function not works for summary values.
Regards,
Xiaoxin Sheng
Hi @Anonymous,
You can try to use below measure to calculate with switch function.
Measure = SWITCH ( SELECTEDVALUE ( T020[SENS] ); 2; SUM ( ENT[HTMT] ) / SUM ( ENT[DEVP] ); 1; -1 * SUM ( ENT[HTMT] ) / ( SUM ( ENT[DEVP] ) ); BLANK () )
Notice: switch function not works for summary values.
Regards,
Xiaoxin Sheng
Thank you very much , that's working
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
112 | |
100 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
111 | |
92 | |
84 | |
66 |