Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ilyan321
Frequent Visitor

DAX: Is it possible to initialize existing columns as variables in a new table?

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

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

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.

View solution in original post

5 REPLIES 5
v-robertq-msft
Community Support
Community Support

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.

Greg_Deckler
Super User
Super User

@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

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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

image.png

 

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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
    )

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors