Forum Discussion
Power Query: replicate Month1 record to Month 2 & 3 for the quarter
Hello all,
I have the below power query question - Thank you so much!
The data I receive is:
| Date | Headcount |
| 1/1/2023 | 5 |
| 4/1/2023 | 7 |
| 7/1/2023 | 10 |
I need to reshape it into: Reat for the other 2 months of the qtr with the same data as month 1.
| Date | Headcount |
| 1/1/2023 | 5 |
| 2/1/2023 | 5 |
| 3/1/2023 | 5 |
| 4/1/2023 | 7 |
| 5/1/2023 | 7 |
| 6/1/2023 | 7 |
| 7/1/2023 | 10 |
| 8/1/2023 | 10 |
| 9/1/2023 | 10 |
Hi, NM2023
You can try the following methods.
Date table:QUARTER = QUARTER([Date])Column = CALCULATE(MAX('Table'[Headcount]),FILTER('Table',QUARTER([Date])=EARLIER('Date'[QUARTER])))Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- 123abc
Community Champion
To replicate the Headcount values for the other two months of the quarter in Power Query in Power BI, you can use the following steps:
Load your initial data into Power Query.
Create a custom column that contains the quarter of each date. To do this, go to the "Add Column" tab and select "Custom Column." Use the following formula to extract the quarter:
Date.QuarterOfYear([Date])
Expand your data to include all months within each quarter. To do this, use the following steps:
a. Duplicate your query by right-clicking on it in the Queries pane and selecting "Duplicate."
b. In the duplicated query, filter for the first month of each quarter. You can do this by keeping only rows where the quarter equals 1. This will give you only the first month of each quarter.
c. Rename the duplicated query to something like "QuarterStart."
d. Create a custom column in the "QuarterStart" query that generates a list of dates for the entire quarter using the List.Dates function. For example:
List.Dates([Date], 90, #duration(1, 0, 0, 0))
e. Expand the custom column to get a list of dates for the entire quarter.
f. Merge the "QuarterStart" query back into your original query using a left outer join on the "Date" column.
g. You should now have a table that includes all the dates for each quarter along with the corresponding "Headcount" values.
Remove unnecessary columns and reorder columns as needed.
Close and load the modified query back into Power BI.
Your final table will contain all the dates for each quarter with the corresponding "Headcount" values from the first month of that quarter.
- v-zhangti
Community Support
Hi, NM2023
You can try the following methods.
Date table:QUARTER = QUARTER([Date])Column = CALCULATE(MAX('Table'[Headcount]),FILTER('Table',QUARTER([Date])=EARLIER('Date'[QUARTER])))Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.