Forum Discussion
Fill values that don't exist with values from another column
I have a table with a column with missing values, I want to fill those missing values with a column in another table.
I created this sample data as an example (sample_data.pbix) :
Table A
| date | value_A |
| Friday, 13 September, 2024 | 1623 |
| Sunday, 15 September, 2024 | 9584 |
Table B
| date | value_B |
| Friday, 13 September, 2024 | 5483 |
| Saturday, 14 September, 2024 | 9084 |
| Sunday, 15 September, 2024 | 1234 |
dates
| date | week_id |
| Friday, 13 September, 2024 | 37 |
| Saturday, 14 September, 2024 | 37 |
| Sunday, 15 September, 2024 | 38 |
The relationship between the tables are as follows using "date" as the key between them.
what I need to do is create a column with the values of column "value_A" from Table A, and fill the missing values (in this case the value for September 14th) with the values of "value_B". In this case, the column should have the values: 1623, 9084, 9584, for each date respectively.
I'm not really sure how to determine when a row in Table A doesn't exist. Table dates has the complete set of dates but I should leave that table intact. Table B may or may not have all the values, so I should leave a 0 if both Table A and Table B don't have that particular date.
Does anyone have directions for me to achieve this?
Thanks in advance.
Read about COALESCE
2 Replies
- lbendlin
Super User
Read about COALESCE
- ramasaurioFrequent Visitor
Perfection.
Thank you!
Edit:
The subtotals looks off, it show the same value as value_A. I'll play with it a bit more and see how it works.