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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Willbw02
Frequent Visitor

Stacked Bar Chart Help - sum of payments by category across dates

I'm new at this and I'm banging my head against my screen trying to figure this out.  😫

 

I have two categories of payments, 1 & 2.  Each payment has a projected payment date.  I'd like to get a stacked bar chart showing the SUM of the payment amounts by month across those two categories.  I feel like I'm running into errors creating this with wither linking to my Calendar Table and/or figuring out how to unpivot my data.  Example table is below.

 

 

Order NumberOrder DateCustomerSales RepTotal PricePayment 1Payment 1 DatePayment 2Payment 2 Date
10015/1/2023DeltaMike25600.0025600.0012/3/2023  
10025/23/2023BravoMolly21578.0010789.0011/5/202310789.006/9/2024
10036/1/2023AlphaMike36296.0018148.0011/9/202318148.006/25/2024
10046/14/2023AlphaPeter95024.0095024.005/1/2025  
10056/8/2023BravoJohn13745.006872.508/19/20246872.508/30/2025
10066/8/2023AlphaMike18364.009182.0011/7/20239182.005/1/2024
10077/9/2023CharlieJohn48364.0048364.003/1/2024  
10087/25/2023CharlieJohn25600.0012800.006/1/202412800.0010/1/2024
10097/29/2023CharliePeter16573.0016573.001/5/2024  
10108/4/2023DeltaMike13587.0013587.004/7/2024  
10118/5/2023BravoMolly13248.006624.009/25/20236624.004/1/2024

 

Any help is much appreciated.

Thanks

Willbw02

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Willbw02 yes, it will work with as many payment types, see attached, You can tweak the solution as you see fit. The core logic is in data preparation in the PQ.

 

PS: There are a few more tables in the attached pbix, just ignore those.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

This M code will transform your data into one that will be amenable to easy analysis/slicer creation.

Hope this helps.

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Removed Columns" = Table.RemoveColumns(Source,{"Total Price"}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {"Order Number", "Order Date", "Customer", "Sales Rep"}, "Attribute", "Value"),
    #"Extract payment instance" = Table.AddColumn(#"Unpivoted Other Columns", "Payment instance", each Text.Middle([Attribute], 8, 1), type text),
    #"Added Custom" = Table.AddColumn(#"Extract payment instance", "Nature", each if Text.Contains([Attribute],"Date",Comparer.OrdinalIgnoreCase) then "Date" else "Payment"),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"Attribute"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns1", List.Distinct(#"Removed Columns1"[Nature]), "Nature", "Value"),
    #"Removed Columns2" = Table.RemoveColumns(#"Pivoted Column",{"Payment instance"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns2",{{"Order Number", Int64.Type}, {"Order Date", type datetime}, {"Customer", type text}, {"Sales Rep", type text}, {"Payment", type number}, {"Date", type datetime}})
in
    #"Changed Type"

Ashish_Mathur_0-1693440308548.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
parry2k
Super User
Super User

@Willbw02 Indeed, it is all about preparing the data in a format that is scalable and can deliver the reports.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Willbw02 yes, it will work with as many payment types, see attached, You can tweak the solution as you see fit. The core logic is in data preparation in the PQ.

 

PS: There are a few more tables in the attached pbix, just ignore those.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Willbw02  Is this what you are looking for?

 

parry2k_0-1693341471635.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Yes, @parry2k ,  Can you please share with me the steps you took to get here?   And... would your method/solution change if there were more than two payment types, like 4 or 5 different types?

Thanks so Much - super helpful!   So its a series of merged unpivots to get rid of all the cross-tabulated info.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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