Variables - The Whiteboard #05

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • A variable is a constant in DAX. Is it more clear if we draw it?
    Learn abstract DAX concepts in a more interactive way with "The Whiteboard" series. Read more: www.sqlbi.com/...
    #thewhiteboard

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

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

    Awesome! 🎉

  • @RC-nn1ld
    @RC-nn1ld ปีที่แล้ว +2

    Lightbulb moment, I understand it now, great format

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

    Más claro imposible!!! Enjoy DAX

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

    This is gold

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

    Awesome😎😎

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

    Thanks, very helpfull

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

    Very well explained and useful.
    I find using Variables on row context more helpful, because they actually get to capture the different values as defined on each row calculation!
    For example:
    Sales Previous Day =
    VAR PreviousDay = Calendar[Date] -1
    Return
    Calculate(Sales,
    Calendar[Date] = PreviousDay)
    However, this might be very resource demanding when having large datasets.
    Would be awesome to see a video on it!

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

    Hey Marco,
    Very good what you do, i'm learning a lot with you, appreciate it.
    I have a small point, maybe for Average sales it's avgsales =divide( salesamount, countrows(distinct(sales[customerskey])))
    because in customers table there is customers who did not bought any product in sales table.
    Thank you

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

      It always depends on the goal to achieve - in general, you're right, but probably it was out of scope for this video.

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

    Thank you very much Mr. Marco. Now i don't have no complexes with Variables. Approximately it was a bit clearly that VAR is constant but I was't not sure.

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

    Marco you rock as usual! GRAZIE for sharing your knowledge with all of us. Maybe next time, would be also very interisting to deeper analyze when make sense include a variable inside a function like CALCULATE

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

    So Variable is to hold a constant result and should not be mistakenly used as if it is a Measure, which can be referred and recomputed with other expressions.

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

    Almost did 6:00 yesterday. Almost forgot that you can't define a measure as a VAR. I suppose you could use DEFINE MEASURE to add a temporary measure inside another measure definition?

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

      You can use DEFINE MEASURE only in DAX queries, not inside a measure definition (e.g. no use in Power BI)

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

    Why hurry with the pen? Take your time for handwriting. Anyway thanks for the video, your content is awesome.

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

      ... Why?

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

    Enjoying this series, one thing I'm very unsure about is when a variable needs to be declared within an Iterator, e.g. SUMX(
    Table1,
    VAR aregion = Table1[Regeion]
    RETURN
    RELATED( Table2[Budget] )
    / COUNTROWS(
    FILTER(
    ALL( Table1 ),
    as opposed to declaring at the very start as you would for MAX ( date ) in a cumulative total. I was re reading the chapter on Variables earlier this week and thought I'd grasped it, then decided I didn't really understand after all. any advice? I admit I have brought this up before. Sorry.

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

      The variable is evaluated in the evaluation context (row and filter) where you defined it. Then it's a constante and it's only used. I hope it helps!

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

    Speaking of variables: is there a way to evaluate a datatable() stored as variable against a model? Whatever I try, i cannot reference any of the columns of that "variable table".
    The use case is when you want to pass a table as a variable in a dax query via the rest api to have it evaluated against an existing dataset. So far, only managed to do it with separate scalar values and not a full table.

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

      This article+video should clarify the issue: www.sqlbi.com/articles/naming-temporary-columns-in-dax/

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

    Thank you 👍
    So variables that store resulting tables are also static (meaning they do not respect data lineage in model) is that right?💕

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

      Not really. If you store a table in a variable, the data lineage is respected once you iterate or apply the variable to the filter context.

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

      @@SQLBI Thank you 👍

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

    Thank you SQLBI. Could someone please explain why the filter doesnt work against the variable in calculate, but if I created the sales amount as a variable in a measure, e.g., Sales_Amount = VAR __SALES = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] ) RETURN __SALES and then applied a slicer within the report it does filter the variable to red only?

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

      The variable is evaluated in the filter context every measure the Sales_Amount measure is executed. Not sure we understand your question.

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

      @@SQLBI You answered my question. Thank you for clarifying. Simple but not easy 🙃

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

    Thanks! I was hoping you would address another issue I always have with table variables.
    I have no idea how to reference a specific column within a result table stored in a variable.
    To me it would be super obvious to do varTable[colName] but this never works.
    any ideas for this?

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

      You must use the original column name in the iterator over a variable that contains a table.

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

      @@SQLBI but that implies I'm using an iterator function. If I just want to do a regular average, median or sum over one column? Is the only option to use the equivalent iterator function and include that column as the only calculation inside the iterator?

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

      @@rob123456hawke If you want to do a SUM from a Table variable you can do so like this: SUMX( Table_Variable, [Column Name]), same for average, just use averagex.

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

    Variables have no business being in CALCULATE 😀