Share via

SSAS-Measures-Calculate function-filter context

jennifer zen 341 Reputation points
2022-05-13T12:49:26.91+00:00

Hello,

A very simple question trying to understand the Calculate function.

For the below measure, If I dont specify the column field for the table in the filter context , then on what basis the sum gets calculated. If I dont specify the column name for the table 'product' it still gives me the same result as when used any of the field (Product[color],Product[name]) on the table? how does this logic works? please can someone explain it to me please?

ex:
calculate ( sum (sales[TotalAmount],Product)
calculate ( sum (sales[TotalAmount],Product[color])--same result as above
calculate ( sum (sales[TotalAmount],Product[name])--same result as above

Thanks in adv

SQL Server Analysis Services
SQL Server Analysis Services

A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.

0 comments No comments

Answer accepted by question author

Olaf Helper 47,621 Reputation points
2022-05-13T12:57:46.057+00:00

You get the same result, because in query 2 + 3 you added only a dimension attribute, but not value to filter on, like = "Blue"

calculate ( sum (sales[TotalAmount],Product[color] = "Blue")  

See https://learn.microsoft.com/en-us/dax/calculate-function-dax => Examples.

Was this answer helpful?


3 additional answers

Sort by: Most helpful
  1. Alexei Stoyanovsky 3,416 Reputation points
    2022-05-16T11:45:04.907+00:00

    Calculate is arguably the most complex function in DAX, despite its deceptively short syntax and straightforward name. The results of these expressions will vary, e.g., depending on the data model (e.g. using a physical table as a modifier is an ancient way of implementing M2M). You'll have to do quite a lot of reading to master it. https://www.sqlbi.com/articles/introducing-calculate-in-dax/ is currently a good starting point.

    Was this answer helpful?

    0 comments No comments

  2. Farhan Ahmed 1 Reputation point
    2022-05-16T05:02:14.27+00:00

    calculate ( sum (sales[TotalAmount]),Product) --> This is same like (SUM(sales[TotalAmount]) the table is

    calculate ( sum (sales[TotalAmount]),Product[color]) incorrect statement--> calculate ( sum (sales[TotalAmount]),Product[color]="Blue") --->Once you write a column name that means Filter Context will be applied and you need to specify expression of your filter This will be translated like
    [FILTER(All(Sales), Product[Color]="Blue"]

    calculate ( sum (sales[TotalAmount]),Product[name]) --> incorrect statement--> calculate ( sum (sales[TotalAmount]),Product[name] ="Bikes") --> Will be translated to same as above

    Was this answer helpful?

    0 comments No comments

  3. ZoeHui-MSFT 41,551 Reputation points
    2022-05-16T01:35:10.293+00:00

    Hi @jennifer zen ,

    calculate ( sum (sales[TotalAmount],Product)  
    

    This means to get the sum of total amount for all the product.

    calculate ( sum (sales[TotalAmount],Product[color])  
    

    This means to get the sum of total amount for all the product color existed in product table.

    calculate ( sum (sales[TotalAmount],Product[name])--same result as above   
    

    This means to get the sum of total amount for all the product Name existed in product table.

    So basically, they are equal, as we did not filter out any products in product table.

    Regards,

    Zoe


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.