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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Change SQL to DAX

Hi.
I have these 2 SQL clauses I need to use in PowerBI measure.

This one I need to add decimals = Rivisumma alv 0% = SUMX ( 'ol', [price] * ( [quantity] ) / (1 + [alv] /100))
This is how I do it in SQL, but haven't found how to do it in DAX.
SELECT ROUND(SUM(ol.quantity * ol.price / (1 + CAST(ol.alv AS DECIMAL(10, 6)) / 100)), 2) Summa


And this one I have tried multiple IF-statements in DAX, but nothing is working. If ol.price is over 0, then sum ol.quantity. If ol.price is under 0 then decrease from ol.quantity.
SUM(CASE WHEN ol.price > 0 THEN ol.quantity ELSE CASE WHEN ol.price < 0 THEN - ol.quantity ELSE 0 END END) Kpl 

Thanks for any help with these.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

round(SUMX ( 'ol',divide( [price] * ( [quantity] )*1.0 ,(1 + [alv] /100.0))),2)

Change data type to decimal. You can Avoid round by giving it column/measure tools

 

SUMX('ol' , Switch(True(), ol[price] > 0 , ol[quantity] , ol[price] < 0 , -1* ol[quantity] , 0 ))

 

Data Format New Rib.png

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

3 REPLIES 3
hemantsingh
Helper V
Helper V

Try like this in DAX - 

Rivisumma alv 0% = SUMX ( 'ol', [price] * ( [quantity] ) / (1 +  [alv] /100))

Rivisumma alv 0% = 
VAR A = SUMX ( 'ol', [price] * ( [quantity] )
VAR B = 1+ Divide([alv],100,0)
Return
Divide(A,B)

Measure_2 =
Switch(True(),

ol.price >0, sum(ol.quantity),

ol.price < 0, write the comdition here like above,
0
)


 

hope this helps.

 

Regards,

Hemant

amitchandak
Super User
Super User

@Anonymous , Try like

round(SUMX ( 'ol',divide( [price] * ( [quantity] )*1.0 ,(1 + [alv] /100.0))),2)

Change data type to decimal. You can Avoid round by giving it column/measure tools

 

SUMX('ol' , Switch(True(), ol[price] > 0 , ol[quantity] , ol[price] < 0 , -1* ol[quantity] , 0 ))

 

Data Format New Rib.png

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
FarhanAhmed
Community Champion
Community Champion

For the first one you can change the precision of your column in "Columns Tools" ribbon

 

DecimalNumberPrecision.png

 

2nd one you need to create measure like this.

 

_Qty = IF(price > 0,SUM(quantity),SUM(quantity)*-1)

 

 

 







Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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