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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
min-E
Helper I
Helper I

Convert SQL Calculations into DAX - MMC, Average, Discount, Average Discount

Hello,

I have some calculations that work in sql but I cannot figure out in PBI. 

Thank you so much for your help.

 

-MMC

 

 

mmc = SUMX('mytable',[qty]*[price])

 

 

-AvgMMC

-MMDisc

-AvgDisc

 

SQL

 

 

 

select 
item
, sum(qty) as qty, sum(qty*Price) as mmc
, case sum(qty*Price) when 0 then 0 else sum(qty*Price)/sum(qty) end as avgmmc
, convert(decimal(10,2),sum(qty*round((Price * C_adj) * G_adj,2))) as mmcDisc
, case sum(qty*Price) when 0 then 0 else convert(decimal(10,2),avg(round((Price * C_adj) * G_adj,2))) end as avgDisc

 

 

 

 

SQL Returns correct info:

itemqtymmcavgmmcmmcDiscavgDisc
tomato21241.511.5224.710.7

 

here is my data

itemqtypriceg_adjc_adj
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
tomato111.50.931
3 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@min-E 

You need to create four measures as follows:

MMC = SUMX(TableName, TableName[Qty] * TableName[Price])

AvgMMC = DIVIDE([MMC], SUM(TableName[Qty])) + 0

MMCDisc = SUMX(TableName, TableName[Qty] * ROUND((TableName[Price] * TableName[C_adj]) * TableName[G_adj], 2))

AvgDisc = IF(MMC = 0, 0, DIVIDE(SUMX(TableName, ROUND((TableName[Price] * TableName[C_adj]) * TableName[G_adj], 2)), SUM(TableName[Qty])))




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

AmiraBedh
Super User
Super User

I don't recommend the approach of translating SQL or any other programming/querying language to DAX, but you can proceed like the following :

MMC = SUMX('mytable', [qty] * [price])
AvgMMC = DIVIDE([MMC], SUM('mytable'[qty]))
MMDisc = SUMX('mytable', [qty] * ROUND([price] * [c_adj] * [g_adj], 2))
AvgDisc = DIVIDE(SUMX('mytable', [qty] * ROUND([price] * [c_adj] * [g_adj], 2)), SUM('mytable'[qty]))
AvgDisc Direct = AVERAGEX('mytable', ROUND([price] * [c_adj] * [g_adj], 2))

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

min-E
Helper I
Helper I

Both of these have worked and helped me understand much better how this works. Thank you!!! 

View solution in original post

3 REPLIES 3
min-E
Helper I
Helper I

Both of these have worked and helped me understand much better how this works. Thank you!!! 

AmiraBedh
Super User
Super User

I don't recommend the approach of translating SQL or any other programming/querying language to DAX, but you can proceed like the following :

MMC = SUMX('mytable', [qty] * [price])
AvgMMC = DIVIDE([MMC], SUM('mytable'[qty]))
MMDisc = SUMX('mytable', [qty] * ROUND([price] * [c_adj] * [g_adj], 2))
AvgDisc = DIVIDE(SUMX('mytable', [qty] * ROUND([price] * [c_adj] * [g_adj], 2)), SUM('mytable'[qty]))
AvgDisc Direct = AVERAGEX('mytable', ROUND([price] * [c_adj] * [g_adj], 2))

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
Fowmy
Super User
Super User

@min-E 

You need to create four measures as follows:

MMC = SUMX(TableName, TableName[Qty] * TableName[Price])

AvgMMC = DIVIDE([MMC], SUM(TableName[Qty])) + 0

MMCDisc = SUMX(TableName, TableName[Qty] * ROUND((TableName[Price] * TableName[C_adj]) * TableName[G_adj], 2))

AvgDisc = IF(MMC = 0, 0, DIVIDE(SUMX(TableName, ROUND((TableName[Price] * TableName[C_adj]) * TableName[G_adj], 2)), SUM(TableName[Qty])))




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.