Forum Discussion

gbarr12345's avatar
gbarr12345
Icon for Post Prodigy rankPost Prodigy
2 years ago
Solved

Help with Margin measure

Hi there,

 

I'm trying to create a measure to calculate the profit margin for customers using the average unit price and average unit cost as in my data these customers would have multiple transactions.

 

I've tried using a measure which is below but am getting the following error - 

'Too few arguments were passed to the DIVIDE function. The minimum argument count for the function is 2.'

 

I've attached my sample data below:

 

https://drive.google.com/file/d/1Kyg3V90tV7Q2kYmclkHiQgUQO3oYr8zg/view?usp=sharing

 

The measure that I used is below:

 

Margin Test =
Margin Test =
DIVIDE(
    AVERAGEX('Module Sales with Inventory', 'Module Sales with Inventory'[unit price]) - AVERAGEX('Module Sales with Inventory', 'Module Sales with Inventory'[unit cost]), AVERAGEX('Module Sales with Inventory', 'Module Sales with Inventory'[unit price]))
 
Is there a good amrgin measure that I could use using the fields Unit price and Unit cost or if you know of any corrections to the above measure?
 
Many Thanks in advance.
  • Hi gbarr12345 - The issue with the measure you created is that it lacks a necessary argument for the divide function, which expects at least two arguments.

     

    i have commented your dax measure below:

     

    Corrected Measure:

     

    Avg Margin % =
    VAR AvgUnitPrice = AVERAGEX('Sales Table', 'Sales Table'[unit price])
    VAR AvgUnitCost = AVERAGEX('Sales Table', 'Sales Table'[unit cost])
    RETURN
    DIVIDE(
        AvgUnitPrice - AvgUnitCost,
        AvgUnitPrice,
        0
    )
     
    Hope it works
    Did I answer your question? Mark my post as a solution! This will help others on the forum!
    Appreciate your Kudos!!

2 Replies

  • Hi gbarr12345 - The issue with the measure you created is that it lacks a necessary argument for the divide function, which expects at least two arguments.

     

    i have commented your dax measure below:

     

    Corrected Measure:

     

    Avg Margin % =
    VAR AvgUnitPrice = AVERAGEX('Sales Table', 'Sales Table'[unit price])
    VAR AvgUnitCost = AVERAGEX('Sales Table', 'Sales Table'[unit cost])
    RETURN
    DIVIDE(
        AvgUnitPrice - AvgUnitCost,
        AvgUnitPrice,
        0
    )
     
    Hope it works
    Did I answer your question? Mark my post as a solution! This will help others on the forum!
    Appreciate your Kudos!!
    • gbarr12345's avatar
      gbarr12345
      Icon for Post Prodigy rankPost Prodigy

      That worked, thank you so much for your help!!!