Forum Discussion
Anonymous
2 years agoNot applicable
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!
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 _ResultIf it answers your needs, please mark my reply as the solution
2 Replies
- Alex87Solution Sage
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 _ResultIf it answers your needs, please mark my reply as the solution
- AnonymousNot applicable
Thank you a lot, i will try this solution!