Row Context in DAX

Поделиться
HTML-код
  • Опубликовано: 28 мар 2022
  • Understanding the difference between row context and filter context is the first and most important concept to learn to use DAX correctly. This video introduces the row context.
    Article and download: sql.bi/746944?aff=yt
    How to learn DAX: www.sqlbi.com/guides/dax/?aff=yt
    The definitive guide to DAX: www.sqlbi.com/books/the-defin...
  • НаукаНаука

Комментарии • 100

  • @karannchew2534
    @karannchew2534 Год назад +45

    Notes for future revision.
    Row context exist in:
    1. Calculated column. By definition - a column consists of rows, and values are calculated row by row.
    Amt = sales[qty] * sales[price]
    _Works for creating new column, where Amt is calculated row by row, by default.
    2. Measure that include table iteration, FunctionX()
    Amt = SUM(sales[qty]) * SUM(sales[price])
    _Work correctly only in certain situations e.g. the filter (of the the table or visual) is at the lowest granularity e.g. per row, per day per sale per customer.
    _Works also at aggregated level e.g. per month, but it gives wrong result. As it gives Total A of all rows x Total B of all row, instead of Total of "AxB of each row".
    So, to calculate Amt correctly,
    need to first do sales[qty] * sales[price] row by row,
    then sum the results from all rows.
    How?
    How to first multiply row by row, then sum?
    Use an X function that iterates row by row. In this case SUMX.
    How to first multiply row by row, then sum?
    SUMX (row by row multiplication)
    But which row of what table? Specify the table!
    SUMX (table_name, row by row multiplication)
    Similarly, to get an average of a ratio:
    AVERAGEX (table_name, row by row division).
    For FUNCTIONX( table_name, expression_formula), just imagine a new column of is created in table_name, with value from expression_formula for every row. Then, FUNCTION is applied to all rows

  • @snakeeyesOFFICIAL76
    @snakeeyesOFFICIAL76 Год назад +7

    guys ... this the best channel about DAX i have come across in youtube

  • @MaestrosounD
    @MaestrosounD 2 года назад +5

    Nice video, Alberto. It actually is a nice addition to the explanation you gave me about context transition earlier today. It definitely is more clear for me now!

  • @sandeepbarge4699
    @sandeepbarge4699 2 года назад +4

    @Alberto - Thank you so much for starting this series of videos! Looking forward for further videos.

  • @joelngige5776
    @joelngige5776 2 года назад +4

    Great explanation Alberto, thanks. I always thought i knew row context but now i know it better. Bravo!!

  • @LookNumber9
    @LookNumber9 Год назад +1

    What a wonderful teacher. Beautifully done. Thank you!

  • @tacijjola
    @tacijjola Год назад +5

    Wonderful! That's exactly what I needed to get started with DAX. Thank you very much Alberto for sharing your DAX wisdom.

  • @amjadzahid
    @amjadzahid Год назад +1

    We are blessed to have "SQLBI". Thank you!

  • @osPA78
    @osPA78 Год назад +3

    This was a FANTASTIC video on Row Context! I know have a much better understanding of this concept and the roles that an iterator plays. Thank you so much!!!!!!

  • @kerryjiang1294
    @kerryjiang1294 2 года назад +2

    Looking forward to the next video. Very helpful 👍

  • @brunotesser624
    @brunotesser624 2 года назад

    Great video as always, looking forward to the next one for newbies!

  • @vietndk5437
    @vietndk5437 2 года назад +5

    Actually, your explanation requires some effort to understand well about the row context and filter context. But once I got it, it blows my mind. Thanks Alberto. Great video.

  • @atanasprodatanasov9233
    @atanasprodatanasov9233 2 года назад

    Brilliant explanation. Thank you! Please keep doing similar videos.

  • @Wzxxx
    @Wzxxx 2 года назад +2

    Very nice explanation. Probably best i have ever watched. Finally! Thank You
    The code comment in green explains a lot. Such a niuance

  • @tomaszs.4811
    @tomaszs.4811 Год назад +1

    This video is simply great - very well presented and explained

  • @MrPelastus
    @MrPelastus 3 месяца назад +1

    Thanks for this video. I've been struggling to understand the difference between measures and calculated columns for some time now, especially as it relates to DAX formulas. This tutorial helped me understand the difference better.

  • @wayneedmondson1065
    @wayneedmondson1065 2 года назад +2

    Very nice tips! Thanks for demonstrating. Thumbs up!!

  • @gilbertosegoviano7701
    @gilbertosegoviano7701 2 года назад +1

    Thank you so much for the time that you give to explain us. That is amazing

  • @paravej
    @paravej 11 месяцев назад +2

    Great.... Now clear about all aggregate function with 'X' and without 'X'
    And also understand what is ROW CONTEXT exactly
    Thanks a lot!!!

  • @gborka
    @gborka Год назад +3

    Thank you for sharing, really great idea to build the understanding layer by layer:
    *Row Context
    *Filter Context
    *CALCULATE Function
    *Context Transition

  • @sergiocaptuleio1088
    @sergiocaptuleio1088 2 года назад +1

    A última medida foi SHOW!!! Mas uma dica sobre contexto. Parabéns!!!!!

  • @saharlatifi3510
    @saharlatifi3510 2 года назад

    Great. Looking forward for next video.

  • @NicholasEnslow
    @NicholasEnslow 2 года назад +1

    As always, the masters at work!

  • @3pandya
    @3pandya 2 года назад +1

    Thank you so much for this video. You explained it really nicely.

  • @michele37276
    @michele37276 2 года назад +1

    Ciao Alberto, i am new to Power bi and i really appreciate this video(the First i m going through). It Is extremely useful, thanks so much

  • @shashankpandey1019
    @shashankpandey1019 6 месяцев назад +2

    Wonderful, Awesome explanation 👏

  • @vdweghp
    @vdweghp Год назад +1

    Sir, you are the best, period !

  • @PHILIPROYBENEDICTLOUIS
    @PHILIPROYBENEDICTLOUIS 2 года назад +1

    Great Video ! Thank you Alberto.

  • @luchoniv
    @luchoniv 11 месяцев назад +1

    Thank you Alberto, very useful.

  • @robertkiermasz4513
    @robertkiermasz4513 Год назад +1

    Very good, easy to understand now.

  • @myroslavamrochko1908
    @myroslavamrochko1908 3 месяца назад +1

    that's helpful, and i liked how its explined.

  • @user-zu1ky6sr7t
    @user-zu1ky6sr7t 2 месяца назад +2

    I LOVE his approach: watch the video once, twice, three times ... until it becomes boring - because you know/understand the concept!!!
    This is awesome, thank you!

  • @user-kp6vb2xs3w
    @user-kp6vb2xs3w 2 года назад +1

    Great video, thank you!

  • @louism.4980
    @louism.4980 11 месяцев назад

    Thank you, love your explanation! :)

  • @timianalytics7150
    @timianalytics7150 11 месяцев назад +1

    Thank you Alberto... Thank God it's weekend, I'll consume a lot of your videos today. Lol

  • @niavras
    @niavras 2 года назад +1

    Thank you! Great axplanation!

  • @raitup00
    @raitup00 2 года назад +1

    Amazing master class

  • @iulianburlacu
    @iulianburlacu 4 месяца назад +1

    Loved it !

  • @melvin9993
    @melvin9993 Год назад +1

    Great as always

  • @MrMalorian
    @MrMalorian 2 года назад +5

    Perfect, I keep messing up row/filter context when making dax

  • @lukereds9975
    @lukereds9975 2 года назад +1

    very good job, ottimo lavoro grazie!

  • @ed-0075
    @ed-0075 2 года назад +1

    Very good video! Thank you! :)

  • @giorgijsfgsdykTV
    @giorgijsfgsdykTV 2 года назад +1

    Such a great video 👍

  • @ram_qr
    @ram_qr 4 месяца назад +1

    A Great Explanation

  • @xXPhixiusXx
    @xXPhixiusXx 8 месяцев назад

    Another example of why he's one of the GOATs 🐐! 🎉

  • @Gaist-zj8tq
    @Gaist-zj8tq 2 года назад +1

    thanks very useful as Always

  • @jgarale
    @jgarale 2 года назад +1

    thank you very much for the video!!! :D

  • @sergiizelenko4114
    @sergiizelenko4114 2 года назад +4

    Thank you for another amazing video!
    I'm wondering if it is correct to say the following (I'm referring to the code of "Amount Col" with 2 Row contexts (min 13:50 of the video).
    Because "Amount Col" is a calculated column, it's evaluated in row context, therefore calculation we have in SUMX() is calculated for every row of Sales table. Then SUMX() is introducing another filter context over unfiltered sales table and calculated Sales[Quantity] * Sales[Net Price] again for every row. As a result, if we think about number of iterations, SUMX is calculated 13.915 times (number of rows in Sales table) for each row. There are 13.915 rows in the table, so there are 13.915*13.915 iterations to obtain a final result (which is the same for each row, but however calculated individually for each of them).

  • @laurenceabrahams3996
    @laurenceabrahams3996 Год назад +1

    Thank you so much Alberto. You have really explained it well after many years of using Power BI , I now understand it so much better

  • @MarciusMGSouza
    @MarciusMGSouza 2 года назад +1

    Very nice!

  • @pantomima5841
    @pantomima5841 Год назад +1

    You are awesome.

  • @scramiro1
    @scramiro1 2 года назад +1

    Great video! Hope there is a Playlist that aggregates this video with other concept videos.

    • @SQLBI
      @SQLBI  2 года назад +2

      The best way is going through the articles on www.sqlbi.com website - each video is related to an article, there is a better way to connect the videos starting from written content!

  • @fabiocaetano2535
    @fabiocaetano2535 Месяц назад +1

    Thanks

  • @anuragkumar-dm1er
    @anuragkumar-dm1er 2 года назад +1

    Really great. Wish it was at least 1 hour long.

  • @pbihari0214
    @pbihari0214 2 года назад +1

    thank you

  • @MrDenisben
    @MrDenisben 2 года назад +1

    great ... as usual

  • @konstantinvolke4569
    @konstantinvolke4569 2 года назад +2

    @alberto. At 20:00 you mention „the easiest is the filter context“. But I assume you intended to say row context is the easiest to understand ?

  • @sandeepkhawas3367
    @sandeepkhawas3367 Год назад +1

    Dear sir, good expiation would request please create more video's on power bi !

  • @RyanReynolds89
    @RyanReynolds89 2 года назад +1

    I know this is more advanced than the video is aiming for, but:
    in the final code with stacked row contexts, does the concept of Expanded Tables factor in at all?

  • @marcofestu
    @marcofestu Год назад +1

    Grazie Alberto for the video.
    One question, in the measure "Test", shouldn't
    RELATEDTABLE (Sales) be used in the second FILTER function?

  • @dbalkin777
    @dbalkin777 2 года назад +1

    GREAT video (as always). Quick question unrelated to DAX: What tablet are you using to demo at the latter half of the video? I am in the market and have to do a lot of similar demos leveraging MS Whiteboard.

    • @SQLBI
      @SQLBI  2 года назад +1

      You can find all the details here: www.sqlbi.com/blog/alberto/2021/02/14/on-my-recording-gear/

    • @dbalkin777
      @dbalkin777 2 года назад

      @@SQLBI Thank you!

  • @jasKSG
    @jasKSG 2 года назад

    Alberto is the nested SUMX in the end another way of computing something complex from our Fact Table (many side) in our filtering table (1 side) but without calculated column - with column we usually use COUNTROWS.... RELATEDTABLE() but looks to me that Sales[CustomerKey] = Customer[CustomerKey] in the nested sumx could achieve tha same if written correctly

  • @powerbinareal
    @powerbinareal Год назад +2

    TOP!

  • @marvinlobo7683
    @marvinlobo7683 2 года назад

    Hi , I have different I'd with values on multiple dates. I need to find count of distinct Id that has sum of values for last 5 days is zero . Is there is any possible way for adding calculated value in filter in dax

  • @livenere
    @livenere Год назад +1

    How are Dax expression executed? Does the calculation starts from the center out, or the out to in?

  • @oliveroshea5765
    @oliveroshea5765 2 года назад

    Perfetto

  • @filipef.6304
    @filipef.6304 2 года назад +5

    Great as always but one question. In table row context is applied by default, but by using a first argument in function SUMX() we automatically tells table to „ignore row context”? In other words, in physics (-) + (-) = + . Here: Row context + Row context = Scan whole table ? Does this logic make sense?

    • @PeterKontogeorgis
      @PeterKontogeorgis 2 года назад +1

      It doesn’t ignore the row context. For each row, it creates a new row context which scans the entire sales table to give the grand total. So if there are 10,000 rows there will be 10,000 iterations and each one of those does a full scan of the table (another 10,000) rows to produce the same total for each row.

    • @Briefklammer1
      @Briefklammer1 2 года назад

      i agree with your confusion, it was really bad explained... i still dont get it. Why the hell is it creating a full scan for every column? Can you give me an example where I need this behaviour?

    • @jasKSG
      @jasKSG 2 года назад

      @@Briefklammer1 when you need grand total for entire table in the current row in a calculated column.

    • @thevenom6902
      @thevenom6902 2 года назад

      Because result of SUMX (have row contex) is 12.337.640(total number).Calculated column also have row contex, you must calculate this number for each row ,row contex doesnt filter table and pruduced this total number for each row.

  • @AkshayKumar-vd5wn
    @AkshayKumar-vd5wn 2 года назад +2

    Thank you for this lesson. I have a question - What is the main goal of this DAX?
    First it picks the the country USA from Customer, then filters Sales condition and then the final If condition on the Sales condition right?
    So what will this Dax produce?
    Edit:
    Also may I inquire why you used Sumx when you could have used Sum if you wanted to get only the totals. Example: Sum(Filter(
    Any reason I am missing for using Sumx.

    • @TRXSTA38
      @TRXSTA38 Год назад +1

      As he said, this measure was specifically to understand and learn row context, not to be a good, efficient measure.

  • @MahadiHasan-qk5ko
    @MahadiHasan-qk5ko 2 года назад +1

    That means every iterator function works as a row context when creating a measure. I mean SUMX, AverageX....etc.

  • @DIGITAL_COOKING
    @DIGITAL_COOKING 2 года назад

    ahhhh ! as you said "DAX is simple" you start to explain it to " 👌👌 make it easy 👍👍" 🙂

  • @trilokinathsingh5705
    @trilokinathsingh5705 Год назад

    please share the series wise index

  • @user-ro3lx3yt8p
    @user-ro3lx3yt8p Месяц назад

    I'm reading now your excelent book = The Definitive Guide to DAX (2nd edition)
    where you explain ROW CONTEXT transition
    It happens in sitiation when CALCULATE is inside ITERATOR like SUMX ( Ex: SUMX( CALCULATE ) )
    The context transitiom mimics ROW CONTEXT trying to to get the same result as ROW CONTEXT using Filter Context
    (sometimes , if the rows are NOT unique it can lead to double-rows mistakes)
    But there's another situation when ITERATOR like SUMX() is inside CALCULATE ( Ex: CALCULATE(SUMX) )
    In the latter case we'd better call it TABLE CONTEXT (as apposes to ROW CONTEXT)
    Because cotext transition happens not just for individual iterated row (as in the case with SUMX(CALCULATE ) )
    BUT FOR A WHOLE TABLE ! In this case a new termin like "TABLE CONTEXT transition" is more appropriate

    • @SQLBI
      @SQLBI  Месяц назад +1

      Not really. You only have filter context and row context. The context transition transforms the existing row context(s) into equivalent filter(s) in the filter context. Every table function is evaluated in the filter context and returns the rows visible there.

    • @user-ro3lx3yt8p
      @user-ro3lx3yt8p Месяц назад

      then what happens in situation like CALCULATETABLE(SUMX () )
      when iterator is inside CALCULATETABLE?
      SUMX creates row context visible in current filter context created by report visuals
      But as I understand , there's NO context transition here because CALULATE is outside the row context/ Can you pls explaon this situation?

  • @ianalvarez7953
    @ianalvarez7953 Год назад

    Wonderful video alberto, so we can say that a row context its in a nutshell, a for loop right?

    • @SQLBI
      @SQLBI  Год назад

      A row context is generated by an iterator, which is similar to a for loop.

  • @zelim9863
    @zelim9863 Год назад +1

    First of all, many thanks for such great video. I have question, why when you wrote measure as column SUMX(Sales, Sales[Quantity] * Sales[Unite Price]) we get grand total whereas when you write it as measure it works differently(meaning filter context works and it calculates row by row). If anyone can explain it to me I will highly appreciate :)

    • @SQLBI
      @SQLBI  Год назад

      Review how filter context works - check related videos in the article, or look at other content on www.sqlbi.com

  • @YassineLaRegardee
    @YassineLaRegardee Год назад

    Hello community, i think a key idea ,that needs to be noticed, is that a measure can be in one of two shapes , either a single value, or a column of values. And that's why we need to sepecify this thing called context row. A calculated column is always in a shape of a serie of values, thus no need to specify a row context.
    What do you think guys?!!🙄

  • @MrAbrandao
    @MrAbrandao 2 года назад

    how to create a row context in a measure if the data is text?

  • @gregoryoliveira8358
    @gregoryoliveira8358 Год назад

    Hi. Someone could explain my something?
    I wrote the follwing measure to calculate month average.
    Geração Mes =
    VAR dataAtual = SELECTEDVALUE(dCalendario[Date])
    VAR mesAnoAtual = SELECTEDVALUE(dCalendario[Mes Ano])
    RETURN
    IF(
    DAY(dataAtual) = 1,
    CALCULATE(
    DIVIDE([Geração Diaria], COUNTROWS(dCalendario)),
    FILTER(ALL(dCalendario), dCalendario[Mes Ano] = mesAnoAtual)
    )
    )
    I tried to apply a combination between AVERAGEX and SUMX, but I didnot work.
    In other hand, I tried to use EARLIER instead of SELECTVALUE. However, this did not work.
    I dont have performance isues with this measure, but I really want to understand where I lost myself in the conceptions.
    Thanks.

    • @SQLBI
      @SQLBI  Год назад

      EARLIER work only for row context in nested iterators. You should review how that works and - in general - it is better to use variables rather than EARLIER.
      Check this and related articles: dax.guide/earlier/

    • @gregoryoliveira8358
      @gregoryoliveira8358 Год назад

      @@SQLBI Thanks. I just really now that I have not nest iterators.

  • @1tsvaishnav
    @1tsvaishnav 2 года назад

    @Albero : Even if I use
    Amount := SUM ( Sales[Quantity] ) * SUM ( Sales[Net Price] ), I seem to be getting the correct answer in the table visual. I believe this could be potentially due to filter context. So which is better version :
    Amount := SUM ( Sales[Quantity] ) * SUM ( Sales[Net Price] ) OR
    Amount := SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )

    • @1tsvaishnav
      @1tsvaishnav 2 года назад

      For anyone having the same question, I quickly realized after posting this comment that your totals would be messed up even if value in individual rows are correct. Also, if you are using card visual, aggregated answer would be different. So depending on what you are trying to do, one of the formula is correct and other is wrong.

    • @AkshayKumar-vd5wn
      @AkshayKumar-vd5wn 2 года назад

      Hey Trushit, hope you are doing well.
      I had this same problem too and you are right when you put it into Card Visual and the answers are similar but here is where I will say ALMOST similar.
      Sum - Sum is the total of one column. In your example, the total of Sales[Quantity] multiplied by the total of Sales[Net Price]. This is all fine and dandy, looks great and you get the answer. So what's the problem?
      The problem is this is not what Sales Quantity * Sales Net Price means.
      Sumx - Sumx is Sales[Quantity] * Sales[Net Price] individually. Not the total but individually. So if you have 2 columns called Sales[Quantity] and Sales[Net Price] and have 3 rows then Sumx goes to the first row takes Sales[Quantity] number from Sales[Quantity[ column, then takes Sales[Net Price] first number from the Sales[Net Price] Column and multiplies it.
      Then it does the same for 2nd and 3rd row it adds it all up and gives the total.
      Context:
      Key thing to note is context. For example, If your business says we have a data with 10 Quantity and 10 Price and we want to know the total amount then you will use Sumx because you are multiplying every 10 Quality and Price, getting the answer and then getting the total.

  • @starcrosswongyl
    @starcrosswongyl 10 месяцев назад

    How come the =SUMX(FILTER(CUSTOMER,CUSTOMER[Country]="USA"),SUMX(FILTER(SALES,SALES[CustomerKey]=[CustomerKey]),SALES[Quantity]*SALES[Unit Price])) GRAND TOTAL is not showing the right figure?

    • @ram_qr
      @ram_qr 4 месяца назад

      Instead of "USA" try "United States"

  • @amas2010
    @amas2010 2 года назад +2

    Thanks for the video, just in case the Test measure is using "USA" instead of "United States"
    Test =
    SUMX (
    FILTER (
    Customer,
    Customer[Country] = "United States"
    ),
    SUMX (
    FILTER (
    Sales,
    Sales[CustomerKey] = Customer[CustomerKey] &&
    Customer[Age] >= 20
    ),
    IF (
    Customer[Age]

  • @lisamgreenleaf
    @lisamgreenleaf 4 месяца назад

    I'm really struggling with understanding what is meant by iteration 😢

    • @SQLBI
      @SQLBI  4 месяца назад

      SUMX is an iterator: for each row of the table in the first argument, it evaluates the second argument. An iteration is the processing of one row!