This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA 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.
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:
| item | qty | mmc | avgmmc | mmcDisc | avgDisc |
| tomato | 21 | 241.5 | 11.5 | 224.7 | 10.7 |
here is my data
| item | qty | price | g_adj | c_adj |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
| tomato | 1 | 11.5 | 0.93 | 1 |
Solved! Go to Solution.
@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])))
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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))
Both of these have worked and helped me understand much better how this works. Thank you!!!
Both of these have worked and helped me understand much better how this works. Thank you!!!
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))
@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])))
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 29 | |
| 27 | |
| 25 | |
| 20 | |
| 14 |
| User | Count |
|---|---|
| 53 | |
| 47 | |
| 22 | |
| 19 | |
| 18 |