Forum Discussion
Create Column as List of Values using M
Hello,
Am new to Power Query so looking for a guiding hand.
I have a table with Contract Start Date and Contract End Date. I have converted these dates to text values YYYYMM (but not sure if this was the right thing to do).
I have a Duration (months) that I have calculated.
Record No. Duration Start YearMonth End YearMonth
| 12 | 9 | 202003 | 202011 |
| 27 | 12 | 202004 | 202103 |
| 97 | 15 | 201910 | 202012 |
I believe what I need next is to generate a Column with a list of values so for each Record ID I have the entire list of applicable YYYYMM values. In the end, I am trying to calculate a monthly revenue stream for each contract no.
Any help or guidance would be very much appreciated.
Kind Regards,
Hi rsbin
you're nearly there!
You have to make an adjustment in the red area:
= Table.AddColumn(Source, "ListofDates", each Date.DatesBetween([Contract Start Date],[Contract Expiration Date],"Month"))
That has to match the name of the query/function where you've posted my code. "." will not be allowed in query names, so it must be something else 🙂
7 Replies
- Greg_DecklerCommunity Champion
Not entirely certain what you are trying to ultimately accomplish. Sometimes it is good to just show your source data and what you are trying to achieve and let people get creative. However, it kind of sounds like you are dealing with date intervals (start and end dates) and need to extrapolate what is in the middle. See if these two posts help. They are DAX but both were designed to deal with such situations.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364#M147
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Revenue-Reverse-YTD/m-p/373185#M111
- ImkeFCommunity Champion
Hi rsbin ,
you can use this function to create the months between your date fields: https://www.thebiccountant.com/2017/12/11/date-datesbetween-retrieve-dates-between-2-dates-power-bi-power-query/
Please check out this video on how to use such a function code in Power Query:
Reuse M code (M functions) created by others easily
- rsbinCommunity Champion
Thank you both for the replies. I will study them over the weekend and let you know