"Power BI - Row Context"
In my previously article, I explained the "Filter Context" in detail. The link of article given below.
In this article we will go through the "Row Context" concept.
DAX Function \ Formula operates in 2 phases:-
1) Valuation context
2) Depending on the function used by user, DAX makes a decision whether to go for "Filter Context" or "Row Context"
Let's begin.
1) Data:-
We will use the same dataset we used in the "Filter Context" example.
2)
"Row Context" is a row aware operation, I will try to explain what I mean in example below.
Suppose we have a requirement where we want to calculate margin earned, based on year.
For year 2015 (margin is 5%)
For year 2016 (margin is 4%)
For year 2017 (margin is 7%)
For year 2018 (margin is 10%)
For year unknown (not present in list above) (default margin to 5%).
To achieve this we will add the DAX code below as a new Measure (Unit_Sales_Margin).
I have tried to depict the same example in Excel, on how it works!
I am aware that the task above can be done more efficiently by different means, but just wanted to make a point on how "ROW context" functions, and much more complex logic can be written as per requirement.
"Row Context" is row aware
(data in different column within the same row is visible to DAX function)
Since "ROW Context" operates at row level, it gives you more control over what you can do with data manipulation operations, as compared to "Filter Context"
Hope this clarifies the concept of "ROW context", do let me know your thoughts on the same.