Forum Discussion

andybrace's avatar
andybrace
Frequent Visitor
1 year ago
Solved

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...
  • MFelix's avatar
    1 year ago

    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]
    		)

     

     

    See file attach