Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi, I am new to DAX. I have 2 questions on initializing variables, specifically initializing columns as variables (VAR) :
1. Is it possible to initialize columns (from existing tables) as variables in a new table?
2. Is it possible to create new columns as variables in a new table and the variable is then used to be referred to other calculations in the same table?
P/S: I may not good in explaining things since I am new to this, sorry about that. You can just reply me if you don't understand my questions. Thank you
Solved! Go to Solution.
Hi,
According to your description, here’s my opinion on your two questions:
For the first one, I think it’s not possible if the column you used in the table has a relationship with your current table, if so, you can simply use the Related() function in the DAX to create a calculated column like this:
Column= Related (‘Table2’[Column2])
https://docs.microsoft.com/en-us/dax/related-function-dax
For the second one, I think the example posted by Greg is a very great example, you can achieve this through his suggestions.
Thank you very much!
Best Regards,
Community Support Team _Robert Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
According to your description, here’s my opinion on your two questions:
For the first one, I think it’s not possible if the column you used in the table has a relationship with your current table, if so, you can simply use the Related() function in the DAX to create a calculated column like this:
Column= Related (‘Table2’[Column2])
https://docs.microsoft.com/en-us/dax/related-function-dax
For the second one, I think the example posted by Greg is a very great example, you can achieve this through his suggestions.
Thank you very much!
Best Regards,
Community Support Team _Robert Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@ilyan321 Not sure what you are going for but this is definitely possible if I understand correctly, like:
Table2 =
VAR __Column = SELECTCOLUMNS('Table',"ID",[ID])
VAR __Table = ADDCOLUMNS(__Column,"One",1)
RETURN
__Table
hi @Greg_Deckler
thank you for your time! i've tried using your method but there is an error. do you know why this happen? thank you
@ilyan321 In your first VAR columnstep1 you add a Date and Country column. But then in your second VAR tablestep1 you base this on columnstep1 and then try to add Date and Country columns again. They are already there, you do not need to add them again.
I see, thank you!
I continue doing it now, and I have another quetions for you. Do you know how can i initialize the code below as a variable - VAR so that i could take a column (from the code) for the next step of calculation? I have tried using SELECTCOLUMNS function but can't seem to get it right
forecasting_uoa_transactions_step1 =
FILTER (
SUMMARIZE (
uoa_transactions_history,
uoa_transactions_history[Date],
uoa_transactions_history[Country],
"UoA", SUM(uoa_transactions_history[Total Changes])
),
DATEDIFF(uoa_transactions_history[Date],TODAY(),MONTH)<variable_uoa_per_cust_window[Variable_UoA_per_Cust_Window Value]+1
)
User | Count |
---|---|
41 | |
27 | |
23 | |
19 | |
16 |
User | Count |
---|---|
55 | |
35 | |
21 | |
18 | |
15 |