Forum Discussion

hamzashafiq's avatar
hamzashafiq
Kudo Collector
3 years ago
Solved

Insert 12 Rows for each ID in Power Query

Hey Guys,

 

I have a dataset, I want to insert 12 rows for each ID in the table using Power Query and insert blank in other records except ID. How can I do that?

Data:

IDMonth YearSales
1May-2220
2Jun-2223
3Jul-2250
4Aug-22100

 

Required Table:

IDMonth YearSales
1Jan-220
1Feb-220
1Mar-220
1Apr-220
1May-2220
1Jun-220
1Jul-220
1Aug-220
1Sep-220
1Oct-220
1Nov-220
1Dec-220
2Jan-220
2Feb-220
2Mar-220
2Apr-220
2May-220
2Jun-2223
2Jul-220
2Aug-220
2Sep-220
2Oct-220
2Nov-220
2Dec-220

7 Replies

  • HI hamzashafiq 
    In order to achieve the desired result, follow these steps
    1. Load the IDs and months table

    2. Append it to your sales table

    3. Add to the result table column concatenates date with ID

    4. Remove Duplicates (based on the merged column) 
    5. Replace null with zero on the sales column :

    5. Remove unnecessary column ("merged")

     

    6. Uncheck "enable load" on unnecessary table

    Link to sample file 

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly



    • hamzashafiq's avatar
      hamzashafiq
      Kudo Collector

      Thanks Ritaf1983 for the solution but the problem is that, how to load the IDs and Months data, that ID is not static. We have thousands of Ids.

    • hamzashafiq's avatar
      hamzashafiq
      Kudo Collector

      Hi Ahmedx I tried your solution and it's working thank you. Now let's see how the actual data looks like.

       

      Data   
      IDGroupYear MonthTransaction Amount
      1History StartJan-2310
      1SalesFeb-2320
      1SalesMar-2330
      1SalesMay-2340
      2History StartMar-2310
      2SalesApr-2320
      2SalesMay-2330
      2SalesJul-2340

       

      In the data you see for each ID (1 and 2) one of the month is missing (ID 1 miss April and ID 2 miss June), we need to insert only that row which is missing, the insertion should start from the date where Group = "History Start" and end at Max date of "Year Month" for each ID. Below is the required output.

       

      Output   
      IDGroupYear MonthTransaction Amount
      1History StartJan-2310
      1SalesFeb-2320
      1SalesMar-2330
      1SalesApr-230
      1SalesMay-2340
      2History StartMar-2310
      2SalesApr-2320
      2SalesMay-2330
      2SalesJun-230
      2SalesJul-2340