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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
kattlees
Post Patron
Post Patron

Pivot with multiple values

Wondering if this is possible. I have tried pivot but it gives an error when there is the same date/time and customer.

 

I have a table of 

Customer

Date/Time

Task

 

If a customer has two tasks at the same date/time, I would like it moved into one row like

Customer    Date/Time   Task 1      Task 2

 

If they have two tasks at different dates/times, I would keep it like this

Customer    Date/Time   Task 1

Customer    Date/Time   Task 2

 

CustomerDate/TimeTask 
12345610/20/2020 8:00Task 1 
12345610/20/2020 8:00Task 2 
65432110/20/2020 9:45Task 1 
98754110/20/2020 11:30Task 1 
98754110/20/2020 21:00Task 2 
    
    
    
End Result   
CustomerDate/TimeTask 1Task 2
12345610/20/2020 8:00Task 1Task 2
65432110/20/2020 9:45Task 1 
98754110/20/2020 11:30Task 1 
98754110/20/2020 21:00Task 2 
4 REPLIES 4
BA_Pete
Super User
Super User

Hi @kattlees ,

 

Are there only ever a maximum of two tasks? You could produce exactly what you want in Power Query, but it would take some gymnastics.

 

Would the follwing work instead?

BA_Pete_0-1604072821358.png

 

You can acheive this by just selecting the [Task] field in Power Query, then selecting 'Pivot Column', set 'Values column' to [Date/Time], open advanced options and select 'Don't aggregate'.

 

The broader question is: Why do you want to do this? You are actually moving the data structure away from the most efficient and 'normal' way of storing it.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Not sure I explained myself well.

 

We have a customer come in and do Task A, Task B, Task C (can be up to 4 or 5 tasks)

 

We bill that customer for all tasks and have costs associated with it.

 

Trying to get charges and cost for each customer based on Task to get average charge/cost per task.

 

Charges and cost show by day and aren't assigned to each task individually.

 

Problem is if someone comes in and does task a,b and c and all charges are grouped by day, it skews the totals because they have 3 tasks so the charge/cost is more than somoene who comes in and just does task a.

 

I need the outcome to list a columns with all tasks done, all charges and all costs.

mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do this in the query editor.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjE1U9JRMjTQNwIhIwMFCysDA6BISGJxtoKhUqwOYVVGYFVmpibGRoaoqiytTExRzbK0MDc1QVNlaGhlbEBYmZEhqp2xAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, #"Date/Time" = _t, Task = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date/Time", type datetime}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer", "Date/Time"}, {{"TaskList", each Text.Combine([Task],";")}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Grouped Rows", "TaskList", Splitter.SplitTextByDelimiter(";", QuoteStyle.Csv), {"TaskList.1", "TaskList.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Split Column by Delimiter",{{"TaskList.1", "Task 1"}, {"TaskList.2", "Task 2"}})
in
    #"Renamed Columns"

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@kattlees , Try pivot in power query

https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.