Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

how to calculate the turnover in powerbi

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 . Capture.PNG

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Thank you very much ,  that's working 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.