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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Conditional unpivoting date columns in power query

I have multiple Excel files containing unit forecasts for different weeks ahead. For each week, a new Excel file containing new generated weekly forecasts (different number of week column compare to previous one) will be produced. I wish to do conditional unpivoting to those date columns. The "Unpivot Columns" or "Unpivot other columns" do not work as the number of date columns in the first sample file is different with the subsequent files. 

 

First file:

(17 week columns)

first file.PNG

 

 Second file:

(could be 17 or more week columns )

second file.PNG

 

 

Is there anyway to do conditional unpivoting? something like Table.Unpivot (if column=date).

I am new in Power Bi. Thank you in advance.

 

1 ACCEPTED SOLUTION

7 REPLIES 7
Vijay_A_Verma
Super User
Super User

Use Unvpivot other columns in your sample file. This means selecting those columns which are fixed say Category, regions etc and then right click - Unpivot other columns. This would take care of other columns's variability. 

Anonymous
Not applicable

I have tried this, however, it only unpivots the columns with the same attributes names. For example, in the first file, I had highlighted the columns other than date columns and selected 'unpivot other columns'. After I uploaded the second file, the power query only unpivots until 3/21/2022 column, the rest starting from 3/28/2022 were ignored.

 

Use this as your Unpivot command (replace #"Changed Type" with your previous step)

= Table.Unpivot(#"Changed Type", List.RemoveNulls(List.Transform(Table.ColumnNames(Source),(i)=> try Text.From(Date.FromText(i)) otherwise null)), "Attribute", "Value")

 

Anonymous
Not applicable

Unfortunately, it comes with this errorerror.PNG

 

Can you give me your Excel file with 2-3 lines of data? You can change the data if the data is confidential.

Please upload the file without confidential/sensitive data to a cloud storage service such as Onedrive/Google Drive/Dropbox/Box (Onedrive preferred) and share the link here.

Anonymous
Not applicable

https://drive.google.com/drive/folders/1fkjomtnrIDO0AFYm_X081mkRTgDvYbPn?usp=sharing

 

Here is the dataset. I had to manipulate the data since it is confidential. The column names remain the same, only the row data changed. Basically, I need to create a dashboard to calculate the changes of forecasted unit between the same dates for different files generated every week. Really appreciate if you can help. Thank you.

This works perfectly well. Download from here...

https://1drv.ms/x/s!Akd5y6ruJhvhuVI8N1IqO6tf0gZK?e=BSor7m 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.