How To Calculate Ratio In Power Bi

How to Calculate Ratio in Power BI

Calculating ratios in Power BI involves using the DAX (Data Analysis Expressions) language and functions. There are several ways to calculate ratios depending on your specific requirement and data model.

Example 1: Simple Ratio Calculation

Let’s assume you have a dataset with two columns: “Sales” and “Expenses”. To calculate the ratio of sales to expenses, you can create a new measure using the following DAX formula:

Sales to Expenses Ratio = SUM('Table'[Sales]) / SUM('Table'[Expenses])

This formula sums up the sales and expenses values and then divides them to get the ratio.

Example 2: Complex Ratio Calculation

In some cases, you may need to calculate ratios based on multiple conditions or calculations. Let’s assume you have a dataset with three columns: “Category”, “Sales”, and “Expenses”. To calculate the ratio of sales to expenses for each category, you can use the following DAX formula:

Category Ratio = 
    CALCULATE(
      DIVIDE(
        SUM('Table'[Sales]),
        SUM('Table'[Expenses])
      ),
      ALLEXCEPT('Table', 'Table'[Category])
    )
  

This formula uses the CALCULATE function to calculate the ratio based on the sum of sales and expenses. The ALLEXCEPT function is used to remove all filters except for the “Category” column, ensuring the ratio is calculated for each category separately.

Applying the Ratio Calculation in Power BI

  1. Open your Power BI report and go to the “Report” or “Data” view.
  2. Select the table or visual where you want to display the ratio.
  3. In the “Fields” pane, click on “New Measure” or “New Column” depending on your requirement.
  4. Enter the appropriate DAX formula for the ratio calculation based on your data model and requirements.
  5. Click on “Enter” or “Apply” to save the measure or column.
  6. Drag and drop the newly created measure or column into your visual or table to display the ratio.

By following these steps and using the appropriate DAX formulas, you can easily calculate ratios in Power BI.

Read more

Leave a comment