Code Generator | DAX

DAX Function for Calculating Ratio

CalculateRatio function in DAX adds values in one column to distinct values in another column, then divides by values in a third column. Easy-to-use for financial analysis in Power BI or Excel.


Empty image or helper icon

Prompt

add column 1 to distinct column 2 and divide by column 3

Answer

/*
Function Name: CalculateRatio
Description: This DAX function calculates the ratio by adding values in column 1 to distinct values in column 2 and then dividing by values in column 3.
Parameters:
- Col1: Column containing numerical values to be added
- Col2: Column containing values to take distinct count before adding
- Col3: Column containing numerical values for division
Return Type: Sum of Col1 + DistinctCount(Col2) / Col3
*/

CalculateRatio = 
SUM([Col1]) + DISTINCTCOUNT([Col2]) / SUM([Col3])

Usage example: Suppose you have a table named 'Data' with columns 'Revenue', 'CustomerID', and 'Expense'. To calculate the ratio based on the described logic, you can create a new column using the CalculateRatio function.

NewColumn = Data[CalculateRatio]

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

CalculateRatio function in DAX adds values in one column to distinct values in another column, then divides by values in a third column. Easy-to-use for financial analysis in Power BI or Excel.