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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
andybrace
Frequent Visitor

Dividing 2 values in same column

Hi all,

 

I have a table with Revenue values and a "multiplier" value.  I have added a "Manuallycalculated" column to show the correct value that I need to calculate - this is calculated at the row level and matches the first 4 columns and divides the matching Revenue (accountID = 1) with the multiplier (AccountID = 2). i.e. rows 1 and 7 match and 100 / 0.8 = 125.

andybrace_0-1740588375124.png

I also have a simple account mapping table:

andybrace_1-1740588427977.png

 

The two are connected with a relationship on the AccountID columns.

 

I am trying to show in a matrix the correct values using DAX measures:

 

Measure_Revenue =
Var _Account = "Revenue"
Var TotalRevenue =
CALCULATE(SUM(FactTable[Value]),
    FILTER(ALL(AccountMapping[AccountName]),AccountMapping[AccountName] = _Account))
RETURN
TotalRevenue
 
Measure_MultipliedRevenue =
Var _Account = "MultiplyFactor"
Var TotalRevenue = [Measure_Revenue] /
CALCULATE(SUM(FactTable[Value]),
    FILTER(ALL(AccountMapping[AccountName]),AccountMapping[AccountName] = _Account))
RETURN
TotalRevenue
 
This is not working as expected, I get:
 andybrace_2-1740588571933.png

This is because it is taking the total Revenue for CatA = 1 and / Total multiplier for CatA = 1... (100+51) / (0.80+0.75) = 97.42.

But, what I want it to do is calculate at the row level and then sum up ... (100/0.80) + (51/0.75) = 193

 

Any ideas how to adjust the DAX to do this?

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @andybrace ,

 

The problem on your calculation is that you need to have the exact order and that is not present on your calculation to do this I believe that the best option is to have a change on the semantic model making the multiplier column next to the corresponding revenue.

 

Do the following:

  • Group by on Account
  • Add a custom column for index for each group
  • Expand the column
  • Select the account and do unpivot by value
  • Rename columns 1 and two to Revenue and Multiplier
  • Add the measures below:
Measure_Revenue = 
SUM(FactTable[Revenue])

Measure_MultipliedRevenue = 
SUMX(FactTable, DIVIDE(FactTable[Revenue], FactTable[Multiplier]))

 

If you want to keep your logic has is you need to:

  • Group by on Account
  • Add a custom column for index for each group
  • Expand the column

Now change your measure for the Multiplier to:

MULITPLIERNEW = 
    VAR tempt = ADDCOLUMNS(
		SUMMARIZE(
			'FactTable (DAX)',
			'FactTable (DAX)'[Index]
		),

		"Revenue", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					1
				},
				'FactTable (DAX)'[AccountID]
			)
		),
		"Multiplier", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					2
				},
				'FactTable (DAX)'[AccountID]
			)
		)
	)
	RETURN
		SUMX(
			tempt,
			DIVIDE(
				[Revenue],
				[Multiplier]
			)
		)


REVENUENEW = 
    VAR tempt = ADDCOLUMNS(
		SUMMARIZE(
			'FactTable (DAX)',
			'FactTable (DAX)'[Index]
		),

		"Revenue", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					1
				},
				'FactTable (DAX)'[AccountID]
			)
		)
	)
	RETURN
		SUMX(
			tempt,
			
				[Revenue]
		)

 

MFelix_0-1740596617648.png

 

See file attach

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
andybrace
Frequent Visitor

Thanks for this.. I haven't had time to try it yet but the second option looks perfect!  I will test it soon and mark it as accepted solution if I can get it to work!.

 

Thanks again!

MFelix
Super User
Super User

Hi @andybrace ,

 

The problem on your calculation is that you need to have the exact order and that is not present on your calculation to do this I believe that the best option is to have a change on the semantic model making the multiplier column next to the corresponding revenue.

 

Do the following:

  • Group by on Account
  • Add a custom column for index for each group
  • Expand the column
  • Select the account and do unpivot by value
  • Rename columns 1 and two to Revenue and Multiplier
  • Add the measures below:
Measure_Revenue = 
SUM(FactTable[Revenue])

Measure_MultipliedRevenue = 
SUMX(FactTable, DIVIDE(FactTable[Revenue], FactTable[Multiplier]))

 

If you want to keep your logic has is you need to:

  • Group by on Account
  • Add a custom column for index for each group
  • Expand the column

Now change your measure for the Multiplier to:

MULITPLIERNEW = 
    VAR tempt = ADDCOLUMNS(
		SUMMARIZE(
			'FactTable (DAX)',
			'FactTable (DAX)'[Index]
		),

		"Revenue", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					1
				},
				'FactTable (DAX)'[AccountID]
			)
		),
		"Multiplier", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					2
				},
				'FactTable (DAX)'[AccountID]
			)
		)
	)
	RETURN
		SUMX(
			tempt,
			DIVIDE(
				[Revenue],
				[Multiplier]
			)
		)


REVENUENEW = 
    VAR tempt = ADDCOLUMNS(
		SUMMARIZE(
			'FactTable (DAX)',
			'FactTable (DAX)'[Index]
		),

		"Revenue", CALCULATE(
			SUM('FactTable (DAX)'[Value]),
			TREATAS(
				{
					1
				},
				'FactTable (DAX)'[AccountID]
			)
		)
	)
	RETURN
		SUMX(
			tempt,
			
				[Revenue]
		)

 

MFelix_0-1740596617648.png

 

See file attach

 

 

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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