Forum Discussion

Migasuke's avatar
Migasuke
Memorable Member
2 years ago
Solved

Is there a difference between automatic measure and simple manual measure?

Hello Experts, I am facing very interesting case where automatic measure (drag and drop) vs simple SUM creates different outcomes. I thought it's the easiest thing evet but does not seem like and ...
  • Sergii24's avatar
    Sergii24
    2 years ago

    Hi Migasuke, thanks for an interesting case! 🙂

    First, to understand the code behind the implicit measure, you can lauch "Performance analyzer" and launch the code in "DAX query view". Within the variable __DS0Core you'll find an interesting filter - "HasDataCosts"

     

    I believe, it's added to the code, to avoid showing potentially "unexisting combinations" in your data model (or better to say combinations that doesn't exist between fact table used in the visual and the table based on which measure is calcualted).

    So PowerBI undertands that you are building a measure on Revenue table, which is connected to DIM Countries, therefore, eventhough you ask to display "DIM Countries" and "Costs" in your visual, it will have only values that exist between "DIM Countries" and "Revenue". 

    To test and confrim this hypothesis, I've created a dummy table and replaced "Country Code" with the column from a new table "TEST_Table". Similarly to the previous case the implicit measure is filtering our unexisting combinations (see DAX query "Implicit measure - new table"):


    Now let's go back to your measure:

     

     

    Measure Revenue = CALCULATE( SUM( Revenue[Revenue] ) )

     

     


    If you compare it with "SumRevenue2" in DAX Query view, the code is identical. However, you don't have a filter 
    "HasDataCosts", that we've discussed above. So what really happens?

    First PBI plots existing combinations of "DIM Countries" and "Costs" (for example AT: AT,CZ,DE, so 3 rows per each row of  "DIM Countries"). What next? Now you're asking to calculate "
    Measure Revenue", which has nothing to do with Costs. So what happens for a row "AT" of "DIM Countries" and "CZ" of "Costs"? Well, the only important part to calculate "Measure Revenue" is the value "AT" of "DIM Countries", because this is the one used to retreive rows of "Revenue" table to sum. Therefore for the existing combintaiton AT (DIM Countries) -> CZ (Costs) you get a calcualtion result, which is based on "AT" from "DIM countries" (and is the same all 3 times until "AT" from "DIM Countries" is filtered). 


    To obtain the real equivalent of the implicit measure, we need to add that "HasDataCosts" filter, which defines if "costs" actually contains a necessary combination of "DIM Countries" and "Revenue". You can obtain it in the following way:

     

     

     

    Measure Revenue (implicit equivalent) = 
    VAR _CountriesFromRevenueSelected = VALUES( Revenue[Country Codes (Revenue)] )
    VAR _CountriesFromCostsSelected = VALUES( Costs[Country Code (Costs)] )
    VAR _Intersection = INTERSECT( _CountriesFromRevenueSelected, _CountriesFromCostsSelected )
    RETURN
        IF(
            COUNTROWS( _Intersection ) > 0, 
            CALCULATE( SUM( Revenue[Revenue] ) ),
            BLANK()
        )

     

     

     


    Here is the final result:

     

     I hope it provided some clarity! have a great day 🙂

    P.S. check pbix attached for more details 😉