Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Making a single row with multiple new columns

Hi, I have an SQL extract that produces a table forecasting the dates for mainteance events but it produces a row for each event, with a single week-year that the activity would take place. I would like to group all the other data and and add extra columns for the recuring events. Is this possible ( I have approximately 7000 rows, and dates going all the way out to the year 2044) ? Thanks in advance.
A sample table and desired results look like:
Sample

SiteIDLocFreqPM NumJP NumTypeWeek
TPOTPO14 WT1436JP4739PM2024-01
HAMHAM13 MZ1049JP8508PM2024-01
WLGWLG/0212 MG1190JP2353CM2024-01
TPOTPO14 WT1436JP4739PM2024-05
TPOTPO14 WT1436JP4739PM2024-09
HAMHAM13 MZ1049JP8508PM2024-13
TPOTPO14 WT1436JP4739PM2024-13
TPOTPO14 WT1436JP4739PM2024-17
TPOTPO14 WT1436JP4739PM2024-21
HAMHAM13 MZ1049JP8508PM2024-25
TPOTPO14 WT1436JP4739PM2024-25

 

Desired result

 

SiteIDLocFreqPM NumJP NumTypeWeekWeek (1)Week (2)Week (3)Week (4)Week (5)Week (6)
TPOTPO14 WT1436JP4739PM2024-012024-052024-092024-132024-172024-212024-25
HAMHAM13 MZ1049JP8508PM2024-012024-13nullnullnullnullnull
WLGWLG/0212 MG1190JP2353CM2024-01nullnullnullnullnullnull


Or the result could be as follows, I don't mind 🙂

SiteIDLocFreqPM NumJP NumWorktype2024-012024-022024-032024-042024-052024-062024-072024-082024-092024-102024-112024-122024-132024-142024-152024-162024-172024-182024-192024-202024-212024-222024-232024-242024-25
TPOTPO14 WT1436JP4739PM1111111111111111111111111
HAMHAM13 MZ1049JP8508PM1000000000001000000000001
WLGWLG/0212 MG1190JP2353CM1000000000000000000000000
  • Hi Anonymous ,

     

    Yo can Pivot the Week by Type.

    Buuuuut. It is advisable to have more columns than to have more columns

     

    Why do you need to do this kind of step in M query?

    If you just want to show the data by week, you can use the matrix visual instead of doing it here

1 Reply

  • mussaenda's avatar
    mussaenda
    Community Champion

    Hi Anonymous ,

     

    Yo can Pivot the Week by Type.

    Buuuuut. It is advisable to have more columns than to have more columns

     

    Why do you need to do this kind of step in M query?

    If you just want to show the data by week, you can use the matrix visual instead of doing it here