Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

A challenging data manipulation problem: counts by dates to single rows

Hi Power BI Community, 

 

I have a challenging data manipulation problem for you...

 

In our org we manage construction projects and allocate assets, people, equipment, etc. to projects. Many of the project forecasts come like this, with each number representing the equipment count for that week: 

 

how data comes.PNG

 

The challenge is that in Power BI, we want it to look like a Gantt Chart. For that I need the data to be in the format below, with each of the counts above being expanded into a row, translating the dates above to a start and end date (note I haven't added 6 days to the end date below to represent the end date of the week, that's an easy step I can do afterwards). My biggest challenge is translating the above table to the below: 

 

how it should look.PNG

 

I look forward to hearing your suggestions. 

1 ACCEPTED SOLUTION
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, I create a table to test:

41.PNG

Please take following steps:

1) Unpivot columns:

42.PNG 

2)Make table group by equipment:

43.PNG

3)Add a custom column to show each equipment’s detail data:

44.PNG

= Table.AddColumn(#"Grouped Rows", "CleanData", each Table.RenameColumns(
  Table.TransformColumnTypes(
    Table.SelectColumns(
      [Data],
      {"Attribute","Value"}
    ),
    {{"Attribute", type date},{"Value" , type number}}
  ),
  {{"Attribute","Date"},{"Value","Count"}}
))

4)Remove grouped column and add a custom column show each record of each equipment:

45.PNG

= Table.AddColumn(#"Removed Columns", "ConvertData", each let 
totalRow = List.Sum([CleanData][Count]),
listTable =  Table.FromList({0..totalRow}, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error),
dataTable = [CleanData],
t1 = Table.AddColumn(listTable,"subTable",each let i = [Index] in Table.SelectRows(Table.AddColumn(dataTable, "NewCount",each[Count] - i),each [NewCount]>0)),
t2 = Table.SelectRows(t1, each Table.RowCount([subTable])>0)
,
t3 = Table.AddColumn(t2, "Start Date",each List.Min([subTable][Date])),
t4 = Table.AddColumn(t3,"End Date", each List.Max([subTable][Date]))
in t4)

5)Expand this custom column and remove other unrelated column, the result shows:

46.PNG

Here is my test pbix file:

pbix 

 

Best Regards,

Giotto Zhi

View solution in original post

4 REPLIES 4
v-gizhi-msft
Community Support
Community Support

Hi,

 

According to your description, I create a table to test:

41.PNG

Please take following steps:

1) Unpivot columns:

42.PNG 

2)Make table group by equipment:

43.PNG

3)Add a custom column to show each equipment’s detail data:

44.PNG

= Table.AddColumn(#"Grouped Rows", "CleanData", each Table.RenameColumns(
  Table.TransformColumnTypes(
    Table.SelectColumns(
      [Data],
      {"Attribute","Value"}
    ),
    {{"Attribute", type date},{"Value" , type number}}
  ),
  {{"Attribute","Date"},{"Value","Count"}}
))

4)Remove grouped column and add a custom column show each record of each equipment:

45.PNG

= Table.AddColumn(#"Removed Columns", "ConvertData", each let 
totalRow = List.Sum([CleanData][Count]),
listTable =  Table.FromList({0..totalRow}, Splitter.SplitByNothing(), {"Index"}, null, ExtraValues.Error),
dataTable = [CleanData],
t1 = Table.AddColumn(listTable,"subTable",each let i = [Index] in Table.SelectRows(Table.AddColumn(dataTable, "NewCount",each[Count] - i),each [NewCount]>0)),
t2 = Table.SelectRows(t1, each Table.RowCount([subTable])>0)
,
t3 = Table.AddColumn(t2, "Start Date",each List.Min([subTable][Date])),
t4 = Table.AddColumn(t3,"End Date", each List.Max([subTable][Date]))
in t4)

5)Expand this custom column and remove other unrelated column, the result shows:

46.PNG

Here is my test pbix file:

pbix 

 

Best Regards,

Giotto Zhi

Anonymous
Not applicable

Legendary! Thanks Giotto, I got it working. 

 

There's no way I would have figured that out on my own. 

amitchandak
Super User
Super User

Anonymous
Not applicable

Hi Amitchandak, 

 

Thanks for your reply, unfortunately this isn't the solution I'm looking for. My number one is the Power Query side where I transform the top table into the bottom table. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.