Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi, row operations like multiply seem a bit tricky in PowerBi to get the correct sums especially.
I would be grateful if someone could help on an efficient way to accomplish this effectively.
For the example multiplying
- [row column} By [row column] in same table
- [row column] by [row column] in different tables
- [row column] by [measure] in same table
- [row column] by [measure] in different tables
- [measure] by [measure] in same table
- [measure] by [measure] in different tables
It seems many of the basic expressions break when combining two different "types" to mulityply with.
I finally found one solution to get the correct sum of a row-by-row multiplicaiton, however for that I did it in two measures. One doing the calculation, in the second using Sumx to get the correct sum.
Solved! Go to Solution.
You may try this:
Net Volume =
MAXX ( RELATEDTABLE ( dtPrice ), dtPrice[Retail Price] )
* ( MAXX ( RELATEDTABLE ( dtDiscount ), dtDiscount[Discount] ) )
* MAXX ( dtQty, dtQty[Qty] )
Cheers!
Vivek
If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂
https://www.vivran.in/
Connect on LinkedIn
Wrapping the expression in Sumx made it work. So now I have the calculations in one expression and a single measure.
For reference for other users, if you need to multiply columns with each other and want to do it using a measure, below code can be used. It is multiplying price with a discount factor and a quantity, to get to a net volume. The measure is created in the PriceTable.
So, source data always helps, Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
- [row column} By [row column] in same table
If calculated column, [Column 1] * [Column 2]
- [row column] by [row column] in different tables
If calculated column in table 1, [Column 1] * MAXX(RELATEDTABLE('Table 2',[Column])
- [row column] by [measure] in same table
If calculated column, [Column 1] * [Measure]
- [row column] by [measure] in different tables
If calculated column, [Column 1] * [Measure]
- [measure] by [measure] in same table
If calculated column, [Measure 1] * [Measure 2]
- [measure] by [measure] in different tables
If calculated column, [Measure 1] * [Measure 2]
Below please find a mockup table with the expected result, following line multiplication, as well as a simple relation model.
The Volume measure is calculated using above formula, and seperately afterwards using Sumx-function.
If there is a decision between using a calculated column or measure, I'd prefer the measure due to its flexibility (as far as I know now).
The aim of the calculation is to from a retail price, multiplying with a discount factor, getting a net price, then multiplying again with corresponding quantity, to get to a net volume, for each part number.
Could you please explain a bit more, D? I am under the impression using the Query editor will create calculated columns. That the measure-option is out of scope in the query editor? If it is easier to do this in the Query editor , then I am all ears. 🙂
@Anonymous wrote:
This stuff should be done in Power Query. DAX is not a language for this. No wonder you guys struggle with things. If you use the right tool for the right job, you'd be saving yourself a lot of time and frustration.
The very fact that something is doable in DAX does not mean it should be done in DAX. Easy as that.
Best
D
Good then we are on the same page. I tried to go all in with getting solutions for all possible combinations, as the code for measures seem to vary depending on if columns and / or measures are used, and I seem to not get them to work, until now after some good help on the way.
Cheers,
Hello @1up ,
You may create a calculated column in your quantity table:
Net Price =
MAXX ( RELATEDTABLE ( dtPrice ), dtPrice[Retail Price] )
* ( MAXX ( RELATEDTABLE ( dtDiscount ), dtDiscount[Discount] ) ) * dtQty[Qty]
Cheers!
Vivek
If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂
https://www.vivran.in/
Connect on LinkedIn
Thanks a lot Vivran.
Is there an expression which will create the same result using a measure?
You may try this:
Net Volume =
MAXX ( RELATEDTABLE ( dtPrice ), dtPrice[Retail Price] )
* ( MAXX ( RELATEDTABLE ( dtDiscount ), dtDiscount[Discount] ) )
* MAXX ( dtQty, dtQty[Qty] )
Cheers!
Vivek
If it helps, please mark it as a solution
Kudos would be a cherry on the top 🙂
https://www.vivran.in/
Connect on LinkedIn
You could simply use value function -
VALUE(TABLE1[COL1]) * VALUE(TABLE2[COL2])
and it works just fine!
Hi, in my example the sum is incorrect unfortunately, 385 vs 463. The bottom row is the Total.
Any idea what could be amiss?
Wrapping the expression in Sumx made it work. So now I have the calculations in one expression and a single measure.
For reference for other users, if you need to multiply columns with each other and want to do it using a measure, below code can be used. It is multiplying price with a discount factor and a quantity, to get to a net volume. The measure is created in the PriceTable.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
13 | |
11 | |
9 | |
6 |