Forum Discussion
min-E
2 years agoHelper 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 -Av...
- 2 years ago
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]))) - 2 years ago
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)) - 2 years ago
Both of these have worked and helped me understand much better how this works. Thank you!!!
AmiraBedh
2 years agoSuper 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))