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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bhill024
Regular Visitor

dates as column names

I am pulling in data from a SQL server database  that is stored vertically (one row per quarter) and pivoting it so I have the  dates as columns. After pivoting, it looks like this:

 

[ID]  [Variables] [2016:2] [2016:1] [2015:4] [2015:3]

 

I am then performing calcuclations (difference, percetages, etc.).

 

What happens when I pull it next quarter and the columns become:

 

[ID] [Variables] [2016:3] [2016:2] [2016:1] [2015:4]

 

? Will my calculations be done correctly, or will the formulas be hard-coded based on the previous dates (columns)? What I need is a way to reference the columns by their position in the dataset, not by their name. Its pretty easy in VBA and R, but I cannot find a solution in DAX.

 

Thanks!

 

 

                                                       

 

2 ACCEPTED SOLUTIONS
KGrice
Memorable Member
Memorable Member

Hi @bhill024. I can't pull from SQL Server right now to confirm, but I don't think the column names will change at all. This is the case if I create a table in Excel, import it, and then go back to the Excel file and change a column header. The table in Power BI retains the original column name.

 

The good news is your calculations won't break, but of course your column headings will be misleading. Is there a requirement to dynamically name the columns? If not, a simple workaround would be to alias the columns as something like CurrentPeriod, CurrentPeriod-1, CurrentPeriod-2, CurrentPeriod-3. If you want to make it more obvious what the corresponding dates are in your report, you could pull the dynamic headings into a separate table as row values, and display them on the report.

View solution in original post

v-haibl-msft
Employee
Employee

@bhill024

 

The columns name should be able to change after you change the quarter in your data source. Then if your calculations reference these columns by name, they will not work anymore.

Based on my testing, the column position will also change after we click Refresh in Power BI Desktop as below. So the workaround provide by KGrice should be a good choice.

dates as column names_1.jpg

 

Best Regards,

Herbert

View solution in original post

3 REPLIES 3
v-haibl-msft
Employee
Employee

@bhill024

 

The columns name should be able to change after you change the quarter in your data source. Then if your calculations reference these columns by name, they will not work anymore.

Based on my testing, the column position will also change after we click Refresh in Power BI Desktop as below. So the workaround provide by KGrice should be a good choice.

dates as column names_1.jpg

 

Best Regards,

Herbert

KGrice
Memorable Member
Memorable Member

Hi @bhill024. I can't pull from SQL Server right now to confirm, but I don't think the column names will change at all. This is the case if I create a table in Excel, import it, and then go back to the Excel file and change a column header. The table in Power BI retains the original column name.

 

The good news is your calculations won't break, but of course your column headings will be misleading. Is there a requirement to dynamically name the columns? If not, a simple workaround would be to alias the columns as something like CurrentPeriod, CurrentPeriod-1, CurrentPeriod-2, CurrentPeriod-3. If you want to make it more obvious what the corresponding dates are in your report, you could pull the dynamic headings into a separate table as row values, and display them on the report.

" If not, a simple workaround would be ... "

 

... but if yes? I want to change column name in data source and I want to reproduce this name to column name.

 

The point is to display names for columns independent on headers on data sets.

 

Table header:

Column1,Column2,Column3 

 

Something like Column1=Year

If i pick Column1 for filtr, filtr displays "Column" name, but i want to display "Year".

 

Thanks for reply

HAS

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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