Variables - The Whiteboard #05

Sdílet
Vložit
  • čas přidán 6. 09. 2022
  • 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/blog/marco/2022...
    #thewhiteboard
  • Věda a technologie

Komentáře • 31

  • @RC-nn1ld
    @RC-nn1ld Před rokem +2

    Lightbulb moment, I understand it now, great format

  • @jorstube
    @jorstube Před rokem +2

    Más claro imposible!!! Enjoy DAX

  • @willianthalles
    @willianthalles Před rokem +1

    Awesome! 🎉

  • @yeyoremix
    @yeyoremix Před rokem +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!

  • @fpa89
    @fpa89 Před měsícem +1

    This is gold

  • @carloromanelli4183
    @carloromanelli4183 Před rokem +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

  • @surajchavan6447
    @surajchavan6447 Před rokem +1

    Awesome😎😎

  • @sbn4862
    @sbn4862 Před rokem +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.

  • @dorotamarkowska5542
    @dorotamarkowska5542 Před 10 měsíci +1

    Thanks, very helpfull

  • @amineazeroil
    @amineazeroil Před 7 měsíci +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  Před 7 měsíci

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

  • @inaction2024
    @inaction2024 Před rokem +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 Před rokem

    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  Před rokem +1

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

  • @williamarthur4801
    @williamarthur4801 Před rokem

    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  Před rokem

      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!

  • @Bharath_PBI
    @Bharath_PBI Před rokem

    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  Před rokem

      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 Před rokem

      @@SQLBI Thank you 👍

  • @OlsoNounas
    @OlsoNounas Před rokem

    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  Před rokem

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

    • @OlsoNounas
      @OlsoNounas Před rokem

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

  • @MrWLKNSN
    @MrWLKNSN Před rokem

    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  Před rokem

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

  • @rob123456hawke
    @rob123456hawke Před rokem

    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  Před rokem

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

    • @rob123456hawke
      @rob123456hawke Před rokem

      @@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 Před rokem

      @@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.

  • @mategombas771
    @mategombas771 Před rokem +2

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

  • @Dzidza1978
    @Dzidza1978 Před rokem +1

    Variables have no business being in CALCULATE 😀