Understanding context transition

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • Context transition is one of the most obscure topics for DAX newbies. Learn how it works, its effects, and how to leverage it rather than be scared of it.
    Article and download: sql.bi/751407?...
    How to learn DAX: www.sqlbi.com/...
    The definitive guide to DAX: www.sqlbi.com/...

ความคิดเห็น • 82

  • @drod96
    @drod96 2 ปีที่แล้ว +40

    Your passion for people to understand the fundamentals is refreshing. I learn so much from you and I am able to address my very specific problems with much more confidence. Thank you so much, I will be hopefully have the pleasure of you and your team help us out as we are rapidly utilizing Power BI for the company I work for. Thank you so much.

  • @user-ro3lx3yt8p
    @user-ro3lx3yt8p 8 หลายเดือนก่อน +2

    the ony thing that I would add to this video is explaning the moment (14:55), that when calculate is impicitly introduced when we use a measure [MaxDate] in expression : FILTER(ALL('Date'), 'Date'[Date]

    • @crownambassador1
      @crownambassador1 5 หลายเดือนก่อน

      Thank you, at the video 14:55 , I was wondering how is this happening that it returns total for all dates. Your explanation made it easy for me to understand. Thank you once again!!

    • @KirahDaw
      @KirahDaw 2 หลายเดือนก่อน

      Thanks for trying to shed some light on this part.. this part of the video really had me confused.. 😕.

  • @masoudpesaran9721
    @masoudpesaran9721 2 ปีที่แล้ว +3

    Been a Power BI trainer for long time, however, learn a new thing every time I see one of your clips. Thank you.

  • @lorenzotillmaniii4273
    @lorenzotillmaniii4273 ปีที่แล้ว +3

    I just keep on repeating all the different videos and its slowly making more and more sense

  • @shayshalev3287
    @shayshalev3287 8 หลายเดือนก่อน +1

    You are the best mentor that I saw not only in youtube but online as a whole

  • @QasimAli-gy3nb
    @QasimAli-gy3nb 2 ปีที่แล้ว +12

    Seen it 2 times, will have to go through one more time to really solidify context transition. Thanks DAX Maestro.

  • @ctew
    @ctew ปีที่แล้ว +10

    Today is the day I found out that you could write a variable within a SUMX function. 🙏 thanks for this awesome content!

    • @sass520
      @sass520 2 หลายเดือนก่อน

      I didn't understand the formula. How variable

  • @willwildwest31
    @willwildwest31 ปีที่แล้ว +2

    I watched the video like 5 times. Now I get it so well. You are a life saver!! I love the way you talk

  • @salvatorescofano6756
    @salvatorescofano6756 2 ปีที่แล้ว +4

    Oh my god, if I had seen this class before Alberto, I wouldn't have wasted so much time fixing project mistakes! thank you so much

  • @shashipaul6279
    @shashipaul6279 ปีที่แล้ว +2

    It is worth to watch every day .... As you find something daily when you are putting your 100% to it .... Thanks Alberto ❤

  • @mwaltercpa
    @mwaltercpa 2 ปีที่แล้ว +3

    I appreciate seeing the explicit writing of equivalent Filter Context in the calculated column.

  • @Zunidrap
    @Zunidrap 2 ปีที่แล้ว +4

    Fantastic explanation and examples. Wish I had known about this a few years ago instead of learning the hard way by trial and error.

  • @mikeycbd
    @mikeycbd ปีที่แล้ว +1

    I've been watching your videos today and they are an excellent building block.

  • @HelloKotha
    @HelloKotha ปีที่แล้ว +1

    Loved every second of the tutorial, learnt a lot. Thanks for your efforts in presenting this.

  • @BISimplifier
    @BISimplifier ปีที่แล้ว +1

    Pure Gold specially for Intermediate users..

  • @davidchang8963
    @davidchang8963 ปีที่แล้ว

    This channel really puts me into a better position when writing DAX, appreciate the great content you guys provided!

  • @joaorataoo
    @joaorataoo 2 ปีที่แล้ว +1

    Watching your videos and learning with you is always so inspiring.
    Thank you so much Alberto.

  • @beginho2454
    @beginho2454 2 ปีที่แล้ว +6

    Thanks Alberto, can not say more thanks to you ;)
    these series really amazing... thanks again

  • @xiaojienan7891
    @xiaojienan7891 6 หลายเดือนก่อน +1

    Thanks you itis the best explaination. DAX really needs someone attention to details , otherwise itis soo easy to make mistakes . Once master it, it’s powerful

  • @joaquimcosta952
    @joaquimcosta952 2 ปีที่แล้ว +1

    The masters of DAX language!!!!

  • @kcmusicable
    @kcmusicable 2 ปีที่แล้ว +1

    I was having this problem today. Thanks for explaining it so elegantly.

  • @ArmandoReportes
    @ArmandoReportes 2 ปีที่แล้ว +2

    9:40 thanks! I really needed to see it like this!

  • @manarzamrik3978
    @manarzamrik3978 2 ปีที่แล้ว +3

    You are great person, make chance for other to learn those precious info for free.

  • @sreenit128
    @sreenit128 2 ปีที่แล้ว +2

    Great explanation for each and every video, .

  • @nidhisingh4973
    @nidhisingh4973 8 หลายเดือนก่อน +1

    Thank you so much for all your awesome videos.

  • @williamarthur4801
    @williamarthur4801 2 ปีที่แล้ว +2

    Really interesting point, re creating max date as a measure, I'd never considered that aspect and not sure I really understand it but thanks to you I'm at least aware of it, will persevere.

  • @bobert13581
    @bobert13581 2 ปีที่แล้ว +1

    the contrasting examples are very helpful! great explanation

  • @joelngige5776
    @joelngige5776 2 ปีที่แล้ว +1

    Well explained as always in a way one is able to grasp the concept.

  • @matthewdufty606
    @matthewdufty606 2 ปีที่แล้ว +1

    Very good. I enjoyed watching this video

  • @scramiro1
    @scramiro1 2 ปีที่แล้ว +1

    Nice way of explainng it! Gracias!

  • @SnonsupSroyer
    @SnonsupSroyer ปีที่แล้ว +1

    Thank you @alberto. ❤

  • @shafa7668
    @shafa7668 2 ปีที่แล้ว +1

    Really nice explanation

  • @karannchew2534
    @karannchew2534 ปีที่แล้ว +5

    Notes for future revision.
    1:25 Context Transition (CT) =
    CALCULATE() transforms any row context to filter context.
    Context Transition =
    CALCULARE() mixes Row context in a table + Filter context from a visual/matrix/formula.
    Context Transition =
    If row context is present, CALCULATE() takes the row context, and use (aka transform aka transit) them as filter, while doing the row-by-row calculation.
    Context Transition happens in every CALCULATE(), which also happen in every [measure].
    Context Transition requires CALCULATE().
    Context Transition also requires row context. Row context exists in:
    1. calculated columns
    2. certain types of functions that iterate through a table e.g. SUMX
    3. table created by FILTER() or other table functions
    /////////////////////
    The first argument of FunctionX() is a table.
    Here,
    SUMX( VALUES( Customer[CustKey] )) returns a table of unique customer keys. With this table, the second argument (from VAR to RETURN) run for each row of the table.
    Sales of big customers =
    SUMX (
    // *Iterate* For each unique customer...
    VALUES ( Customer[Customer Key] )
    // ... get its total sales
    // Use CALCULATE() to combine "each *row of iterated* unique customer" with whatever filter exist in the visual/matrix...
    VAR CustomerSales =
    CALCULATE (
    SUMX ( Sales, Sales[Qty] * Sales[Price] ) )

    // ... otherwise, "CustomerSales=SUMX(Sales,Sales[Qty]*Sales[Price] )" get the sum based only on whatever filter exist in the visual
    VAR BigSale = IF ( CustomerSales >= 5000, CustomerSales )
    RETURN BigSale
    )
    /////////////
    Running Total Sale Wrong =
    CALCULATE (
    [Sales Amount],
    FILTER( ALL ( 'Date' ), 'Date'[Date] CALCULATE() runs through each row of the table!
    // --> FILTER( 'Date'[Date] FILTER ( For all/whole Date table, get 'Date'[Date] FILTER ( All dates lower or same as the highest 'Date'[Date] of the visual/matrix context ).

    • @nidhisingh4973
      @nidhisingh4973 10 หลายเดือนก่อน

      Hi Karan,
      Thank you for detail explanation.
      One doubt related to Running Total correct calculation
      Ideally All(date) removes all filter from date table then how max(date[date]) is computed over visual filter.
      Can you please explain.

  • @eniolaabolade8638
    @eniolaabolade8638 ปีที่แล้ว

    Can’t lie, this video confused my destiny.

  • @DawoodChoudry-r3j
    @DawoodChoudry-r3j 14 วันที่ผ่านมา

    Hi,
    At 4:36 time of the video the measure you have created (Sales of Big Customer), should not you use values(sales(CustomerKey)), because outer visual filters that are coming from rows in the matrix directly apply the filter to the sales table they do not directly effect the customer table we always have the same number of distinct customer return by Values function when we applied this values(customer(CustomerKey)),
    we should use values(sales(CustomerKey)) instead of values(customer(CustomerKey))
    because we can gain performance benefits as well because of this approach?
    Looking forward to your response
    Thanks!

  • @sbn4862
    @sbn4862 2 ปีที่แล้ว +2

    Hi Mr Alberto.Thanck You very much for extra explanations.
    Is a context transition hapens when there is an active context only?
    What about , when i use vareble with temporary calculateing table where i have active context row?
    (and sorry for my bad Englsh)

  • @nishantchawla333
    @nishantchawla333 2 ปีที่แล้ว +2

    Yes, I have a question, that, when we are using context transition, why are we specifically capturing customer values as a variable and making it explicit, it is still the same as implicit right? The value comes out to be same, can you throw more light on it.

  • @Wzxxx
    @Wzxxx ปีที่แล้ว +2

    1. Why SUMX is itarating through VALUES is used instead of ALL? Is there a specific reason for that
    2. Why the VAR is defined in the middle of other function (Sumx)? Does the sumx uses it on the go? Will it work without the VAR inside? I didn't find such concept in the book or on your channel ?
    3. The more important one for me: Why in the last example the MAX(date[date]) is being evaluated in the original context??? It is a part of FILTER(ALL(dates)) calculate argument which REMOVES filter from a date column so it SHOULD remove outer filter context from date? It iterates through date table without filter and now the MAX(date[date]) still uses original context? Where is logic here?

  • @shivamkapoor1827
    @shivamkapoor1827 ปีที่แล้ว

    At 14.26 why the output is same for all the rows. you said that calculate change row context to filter context but their is also outer filter context from matrix view. what about that filter context why that filter context not shows its effect with the other filters that changes from row context to filter context by canculate??

  • @peanut-d-cat
    @peanut-d-cat 2 ปีที่แล้ว +1

    thank you so much sir.

  • @hbird8071
    @hbird8071 2 ปีที่แล้ว +2

    Thank you for this masterclass. Did not even know this concept existed. I just have a question regarding using the SalesAmount code in the Calculated Column without the implicit 'Calculate' that comes from using the measure. In that particular example if we use the Customer Key relationship and use the RELATEDTABLE function would we be able to achieve the same analytical result, and would it be an example of filter context only equivalent or is there context transition?

    • @SQLBI
      @SQLBI  2 ปีที่แล้ว

      RELATEDTABLE is like CALCULATETABLE, see dax.guide/relatedtable

  • @ideakarma7034
    @ideakarma7034 หลายเดือนก่อน +1

    Thank you so much. How did you increase the font size in the formula bar? Is there a keyboard shortcut?

    • @SQLBI
      @SQLBI  หลายเดือนก่อน +1

      CTRL+Mouse Wheel!

    • @ideakarma7034
      @ideakarma7034 หลายเดือนก่อน

      @@SQLBI is there a similar way in Excel too? The settings change isn't as clean.

    • @SQLBI
      @SQLBI  หลายเดือนก่อน +1

      Probably no.... you have to go in Settings, indeed.

  • @vitaliburla8498
    @vitaliburla8498 2 ปีที่แล้ว

    I think one point could be a little unclear is in very the end - if I'm not mistaken, when the context transition happens, the All statement is also converted to filter context, thereby returning the absolute latest date for the table. So it's like Calculate(max(Date[Date]), ALL([Date]) + all the other columns from the row context. Otherwise, if we just call the measure MaxDate, it will return the current date in the respective row, because of the transition. Or maybe I got it wrong and I'll watch again... Thank you very much!

    • @SQLBI
      @SQLBI  2 ปีที่แล้ว

      No, ALL is like REMOVEFILTERS and remove a filter, it does not create any filter.

    • @bgoka
      @bgoka 2 ปีที่แล้ว

      @@SQLBI As I understand correctly basically due to context transition [MaxDate] is under the influence of ALL ( 'Date' ) which removes the filter context (year month) of visual and return maximum date for the whole 'Date' table which then is used for Date[Date]

    • @saravananram3740
      @saravananram3740 ปีที่แล้ว

      @@bgoka no there is an implicit calculate function wrapped around [MaxDate], in both scenarios ALL('Date') is same.

  • @sandeepbarge4699
    @sandeepbarge4699 2 ปีที่แล้ว +2

    Thanks once again for this series.
    So MAX used in last expression to calculate running total the right way is giving maximum date up to currently iterated row introduced by FILTER function and not the max date available in the date table. Right?

    • @olemew
      @olemew 2 ปีที่แล้ว +3

      No. It's calculating the MAX for the current filter context, i.e. year and month of the specific "cell" of the matrix visual.

    • @karannchew2534
      @karannchew2534 ปีที่แล้ว

      @@olemew Hi, I don't get it, please help. Doesn't ALL(date[date]) clear all the filter in the matrix/visual? I understod that ALL() is the same as REMOVEFILTER().

  • @NikitaShilyaev
    @NikitaShilyaev 5 หลายเดือนก่อน +1

    I realize from this video that I'm still not ready to undertsand filter context transition

  • @khalilayari3230
    @khalilayari3230 ปีที่แล้ว

    what happens if we just put 2 nested sumx without the filter transition ? Will the function just ignore the values[customerKey] and just give the sum with the outter filter context ?

  • @gunasekharreddy230
    @gunasekharreddy230 ปีที่แล้ว

    Hi Alberto , I have created a new column of Big customer sales , The inner query should have filter context for each customer , Indeed the same row filter context is applied on every row of orders table , Can you please explain what if we write the Big customers measure as a column

  • @herrsan
    @herrsan หลายเดือนก่อน

    quick question to check whether I understood the concept of context transition correctly. If I were to use "var", context transition would also not be happening, right?
    RT Sales 1=
    var maxdate=
    MAX('Date'[Date])
    var calc=
    CALCULATE(
    [Sales Amount],
    FILTER(
    ALL('Date'),
    'Date'[Date]

    • @SQLBI
      @SQLBI  หลายเดือนก่อน +1

      Context transition would happen only if you write CALCULATE, just MAX would not have triggered the context transition anyway. However, you are right, if the variable gets a value from a measure or use CALCULATE, then the value is stored there and there is no further evaluation when the variable is referenced.

    • @herrsan
      @herrsan หลายเดือนก่อน

      @@SQLBI thank you! I am doing your Master DAX course right now, by the way, and your videos here give me a good opportunity to check what I have learnt in your course so far!

  • @praticandopowerbi
    @praticandopowerbi 2 ปีที่แล้ว +1

    Obrigado professor muito bom a explicação

    • @praticandopowerbi
      @praticandopowerbi 2 ปีที่แล้ว

      Professor faz um vídeo carrinho de compras por cliente

  • @mathijs9365
    @mathijs9365 ปีที่แล้ว

    Context transition is a complex topic if you explain it hard.

  • @ellukayou
    @ellukayou 2 ปีที่แล้ว +1

    I wish understand this before hahah

  • @anuphp3432
    @anuphp3432 ปีที่แล้ว

    why can't just use date['date']

  • @svengrutzmacher945
    @svengrutzmacher945 2 ปีที่แล้ว

    Thank you for this great video! I am just curious: if context transition would happen on the fact table, e.g. SUMX(Sales, CALCULATE(xxx)), does the resulting filter context contain all columns of the sales table or of the expanded sales table? (and thus perhaps all columns of the whole model). After all DAX does always consider the expanded table?

    • @SQLBI
      @SQLBI  2 ปีที่แล้ว +2

      Context transition applies to the expanded table!

  • @benromdhanemohsen2765
    @benromdhanemohsen2765 ปีที่แล้ว +1

    somthing is not clear about a filter date < = max(date) it seems like a totology in fact every date is < or = max date

    • @SQLBI
      @SQLBI  ปีที่แล้ว +1

      The MAX(date) in a measure is evaluated for every cell of the report, if you have a Matrix with months on the rows, every cell produces a different result.

  • @inaction2024
    @inaction2024 2 ปีที่แล้ว

    Please tell me I am not the only one who is more confused after watching this video. :-( So, row context existed in column [Date] because of the using of Filter, which is a iterator, and then the row context was transitioned into filter context because of implicit "Calculate" wrapped around the measure MaxDate. Who can tell me how the newly introduced filter context works after that?
    Also, to me the using of measure MaxDate and the expression of Max (Date [Date]) in the condition doesn't make a real difference in terms of what table it returns. They both return the identical full Date table, doesn't it?

    • @inaction2024
      @inaction2024 2 ปีที่แล้ว +1

      Okay, so here is what I think is actually happening: the context transition created by inexplicit "Calculate" on measure MaxDate created an new internal filter context on the calendar[date] columns, which overrides the existing external filter context applied by visual filter on calendar[date], hence returned the incorrect results. Am I correct?

    • @saravananram3740
      @saravananram3740 ปีที่แล้ว

      @@inaction2024 yes that make sense

  • @ajit78910
    @ajit78910 ปีที่แล้ว

    ❤❣

  • @scramiro1
    @scramiro1 2 ปีที่แล้ว

    Could you even use the following expression to avoid using CALCULATE? Gives same result in my AdventureWorks, but I wonder why better CALCULATE.
    SUMX (
    VALUES( Customer[CustomerKey] ),
    SUMX ( RELATEDTABLE(Sales) , Sales[Order Quantity] * Sales[Unit Price] )
    )

    • @SQLBI
      @SQLBI  2 ปีที่แล้ว +1

      RELATEDTABLE is just an alias of CALCULATETABLE, so you get basically the same context transition behavior.

    • @scramiro1
      @scramiro1 2 ปีที่แล้ว

      @@SQLBI So, RELATED does context transition as of CALCULATE? that explains a lot! I thought several times that RELATED do makes a filter transition, but so far I never read the formula worked as a CALCULATE.

  • @danielabdelsater1541
    @danielabdelsater1541 ปีที่แล้ว +1

    Thank you for this amazing explanation.
    Minute : 15:18 --> you said the MaxDate is not computed in the current filter context, MAXDate is computed in a 'NEW' filter context where the date is only the currently iterated date.
    But, base on the explanation of your colleague : th-cam.com/video/0y1rCOL8DTs/w-d-xo.html
    it should be computed in the current filter context + the row context transformed to a filter context ,
    can someone explain the differnce please ?
    thanks,

    • @SQLBI
      @SQLBI  ปีที่แล้ว +1

      Why do you say that?
      MaxDate is a measure reference, so there is an implicit context transition that converts the iterator where MaxDate is into a filter context that hides the outer filter context over dates. That is a "new" filter context, obtained by the existing filter context (the cell evaluated in the report) + the result of the context transition, which *in this case* overwrites the previous one.