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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
userpien
Helper I
Helper I

CASE SUM from SQL SERVER to Power BI

How to bring this query from SQL SERVER to Power BI. I have to bring this query to a measure in Power BI and I don' t understand how to arrasnge this one. Can you help me?

SQL SERVER:
sum(CASE WHEN anama.ppcoll is null
THEN 0
ELSE
case when anama.ppcoll <> 0
then Vendite."Quantità"/ anama.ppcoll
else 0
end
END)

 

anama and Vendite are the TABLE, ppcoll and Quantità are the columns.


i tried to write this query on Power BI but i don't know if it's right:

Colli = SUMX(
    anama,
    SWITCH(
            ISBLANK(SELECTCOLUMNS(anama,anama[ppcoll])), 0,
            SELECTCOLUMNS(anama,anama[ppcoll]) <> 0, DIVIDE(SELECTCOLUMNS(Vendite,Vendite[Quantità]),SELECTCOLUMNS(anama,anama[ppcoll])),
            0))


Thanks!

1 ACCEPTED SOLUTION
Alex87
Solution Supplier
Solution Supplier

Hello,

Try this:

 

 

Colli = 
VAR _Total = SUM(anama[ppcoll]) 
VAR _Quantity = SUM(vendite[quantita]) 

VAR _Result = 
SWITCH( 
   TRUE(), 
      ISBLANK(_Total), 0,
      _Total <> 0, DIVIDE(_Quantity, _Total), 
   0) 

RETURN _Result

If it answers your needs, please mark my reply as the solution

 

View solution in original post

2 REPLIES 2
Alex87
Solution Supplier
Solution Supplier

Hello,

Try this:

 

 

Colli = 
VAR _Total = SUM(anama[ppcoll]) 
VAR _Quantity = SUM(vendite[quantita]) 

VAR _Result = 
SWITCH( 
   TRUE(), 
      ISBLANK(_Total), 0,
      _Total <> 0, DIVIDE(_Quantity, _Total), 
   0) 

RETURN _Result

If it answers your needs, please mark my reply as the solution

 

Thank you a lot, i will try this solution!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.