Code Generator | DAX

DAX Function for Divided Sum Calculation

This DAX function adds two columns from a table, then divides the sum by values in another column, with error prevention for division by zero. It is adaptable across various scenarios for sum and division calculations.


Empty image or helper icon

Prompt

add 2 columns together and divide by another column

Answer

/*
Function: calculate_divided_sum
Purpose: Add two columns together and divide by another column
Parameters: 
- column1: First column to be added
- column2: Second column to be added
- divisor_column: Column that will be used as the divisor
Return Type: Decimal number
Exceptions: None
*/

calculate_divided_sum = 
DIVIDE(SUM('Table'[column1]) + SUM('Table'[column2]), SUM('Table'[divisor_column]), 0)

This DAX function calculates the sum of two columns ('column1' and 'column2') from a table called 'Table', then divides the result by the values in another column ('divisor_column'). The DIVIDE function is used to prevent division by zero errors by replacing them with a specified default value (0 in this case). The function is reusable and can be applied to different tables or scenarios where such calculations are required.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This DAX function adds two columns from a table, then divides the sum by values in another column, with error prevention for division by zero. It is adaptable across various scenarios for sum and division calculations.