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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

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

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


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

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

 

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



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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