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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
rprice768
New Member

Conditionally Populating Values in Multiple Columns with Variable Headers

Hello all!

 

I'm working on a query that contains contract start and end dates, as well as columns based on week ending dates, for a number of individuals.  The full dataset is much more involved and has many other columns but the key columns for this issue are shown below with some example data.  The "WE" columns start blank, currently.

 

Example:

NameStart DateEnd DateWE 9/14/2024WE 9/21/2024WE 9/28/2024
Person 19/1/202410/26/2024   
Person 29/15/202412/21/2024   
Person 310/14/20241/11/2025   
Person 47/14/20249/7/2024   
Person 57/22/20249/14/2024   

 

Since the resulting report will be "refreshed" periodically and the weeks are added cumulatively, the "week ending" columns to be added by the query will vary.  For each of these "week ending" columns, I need the query to populate "N/A" if that week fell outside each individual's contract dates.

 

Ideal End Result:

NameStart DateEnd DateWE 9/14/2024WE 9/21/2024WE 9/28/2024
Person 19/1/202410/26/2024   
Person 29/15/202412/21/2024N/A  
Person 310/14/20241/11/2025N/AN/AN/A
Person 47/14/20249/7/2024N/AN/AN/A
Person 57/22/20249/14/2024 N/AN/A

 

Since the column names (and weeks they reference) are variable I created a table that populates all the column names and dates to be added to the report.  So far I have not been able to find a way to populate the "N/A"s based on that table; the column names I have working, it seems.

 

I did attempt to use Table.ReplaceValue for each of the columns but could not figure out how to designate a different calculation for "new" value for each column.  (I'll preface this with an apology for any weird code - I'm fumbling my way through this report the best that I can.)  I joined my table of new columns to the main table using an arbitrary "Anchor" column, used FillUp to get the dates populated in each newly added column, and then tried to ReplaceValue my way to a solution but could not get it to recognize more than one date in the "oldValue" section.

 

#"Merged New WE Date Columns" = Table.NestedJoin(#"Replaced Value1", {"Name"}, #"New WE Date Columns", {"Anchor"}, "New WE Date Columns", JoinKind.FullOuter),
#"Expanded New WE Date Columns" = Table.ExpandTableColumn(#"Merged New WE Date Columns", "New WE Date Columns",List.RemoveItems(Table.ColumnNames(#"Merged New WE Date Columns" [New WE Date Columns]{0}), {"Anchor"})),
#"Filled Up" = Table.FillUp(#"Expanded New WE Date Columns",List.RemoveItems(Table.ColumnNames(#"New WE Date Columns"),{"Anchor"})),
Custom3 = Table.ReplaceValue(#"Filled Up", {#"New WE Dates"}, each if [Start Date] > _ or [End Date] < _ then "N/A" else null, Replacer.ReplaceValue, List.Select(Table.ColumnNames(#"Filled Up"), each List.Contains(#"New WE Date Columns (List)",_))),

 

"New WE Date Columns" is the table with the new headers.

rprice768_0-1730835496937.png

"New WE Dates" is a list of only the week ending dates based on the previous table.

"New WE Date Columns (List)" is a list of the headers on the previous table.  This was possibly unnecessary but it made sense in my head.

 

Does anyone have any suggestions on how to populate the WE Date columns while complying with the need for variable headers and conditions?  Any and all help is greatly appreciated, and I am happy to provide additional information if needed.

 

Thank you!

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

One of the first things you will learn when working with Power BI that you need to bring your data into usable format. The term is "unpivoting.

 

From 

lbendlin_0-1730842219135.png

To

lbendlin_1-1730842261939.png

Then you do some cleanup and type casting

lbendlin_2-1730842384273.png

And then you can compute the value

lbendlin_3-1730842546887.png

There is no need to re-pivot the data here, this can be done for free in the matrix visual.

lbendlin_4-1730842800539.png

 

 

 

 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

One of the first things you will learn when working with Power BI that you need to bring your data into usable format. The term is "unpivoting.

 

From 

lbendlin_0-1730842219135.png

To

lbendlin_1-1730842261939.png

Then you do some cleanup and type casting

lbendlin_2-1730842384273.png

And then you can compute the value

lbendlin_3-1730842546887.png

There is no need to re-pivot the data here, this can be done for free in the matrix visual.

lbendlin_4-1730842800539.png

 

 

 

 

Brilliant!  It took a little extra fiddling to get the right columns to unpivot but this worked flawlessly.  Thank you so, so much for your assistance.  I've figured out a decent amount with Power Query but I know I'm missing a good bit of core knowledge so this was a real struggle.  I appreciate you!

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.