How to divide each row of a calculated column by the total of another calculated column?

后端 未结 3 1717
心在旅途
心在旅途 2021-01-16 02:37

I can\'t get a division correct with this sample data:

Calculated column    Another calc. column
   48                  207
  257                  370
  518          


        
3条回答
  •  清酒与你
    2021-01-16 03:20

    Basically, there is nothing wrong with the calculated columns, and both Alexis and StelioK formulas are correct.

    The root problem here is a confusion between calculated columns and measures. You are looking at the results in a conceptually wrong way - through the matrix visual, with several filters active on slicers. If you remove the filters, you will see that the total amount is 140,920, not 82,826. The latter number is the total for the filtered data set, not the entire table.

    To get this right, you need to understand several fundamental concepts behind Power BI:

    • Calculated columns are always static. Once a calculation is completed, it can not respond to slicers or other UI controls. It's just static data, identical to data in non-calculated columns. DAX formulas used to calculate columns are active only when you create them, or upon data reload.
    • If you want your calculations to respond to slicers etc, they must be measures. It's the only way, no exceptions.
    • Avoid calculated columns, they are utterly useless. Power BI is all about measures; I can't think of a single reason for using calculated columns. When you add a column, you are essentially enhancing your source data, because you feel like you are missing something you need for your report. But that need can be much better addressed at the source (database or file you import), or using Power Query, which is designed exactly for this kind of tasks. The best practice is: build your columns at the source, for everything else design measures.
    • Another important advice: never drop fields (columns) into visuals directly. Always write a DAX measure, and then use it. Relying on Power BI auto-aggregations is a very bad practice.

提交回复
热议问题