Variables - The Whiteboard #05

Поділитися
Вставка
  • Опубліковано 2 гру 2024

КОМЕНТАРІ • 32

  • @shubhampawar8506
    @shubhampawar8506 Місяць тому +1

    Great Explanation.. DAX Guru ❤

  • @RC-nn1ld
    @RC-nn1ld 2 роки тому +2

    Lightbulb moment, I understand it now, great format

  • @jorstube
    @jorstube 2 роки тому +2

    Más claro imposible!!! Enjoy DAX

  • @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!

  • @willianthalles
    @willianthalles Рік тому +1

    Awesome! 🎉

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

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

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

  • @amineazeroil
    @amineazeroil 11 місяців тому +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  11 місяців тому

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

  • @fpa89
    @fpa89 5 місяців тому +1

    This is gold

  • @surajchavan6447
    @surajchavan6447 Рік тому +1

    Awesome😎😎

  • @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)

  • @dorotamarkowska5542
    @dorotamarkowska5542 Рік тому +1

    Thanks, very helpfull

  • @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/

  • @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 🙃

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

    • @RobHOUTX46285
      @RobHOUTX46285 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 роки тому

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

  • @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 👍

  • @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!

  • @mategombas771
    @mategombas771 2 роки тому +2

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

  • @Dzidza1978
    @Dzidza1978 2 роки тому +1

    Variables have no business being in CALCULATE 😀