Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi There,
I have production table in below format and i am trying to workout how to put production quantities in monthly buckets. In below example production falls in two months. I want output to show we produced 2600 in Oct (18200/7) and rest of the qty in Nov.
| Production Start | Production End | Production Qty |
| 31/10/2022 | 06/11/2022 | 18200 |
Thanks in advance for your help.
Hi @mudassirmir ,
you can use the function I've published here to create a list of days that allow you to allocate accordingly:
Date.DatesBetween to retrieve dates between 2 dates in Power BI and Power Query – The BIccountant
After that, the count of the items in your list can be used as a divisor to create the daily amount.
Then expand the days, apply the daily amount calculation and aggregate to month, to your liking:
(Please also check the file enclosed):
let
Source = Table.FromRows(
Json.Document(
Binary.Decompress(
Binary.FromText("i45WMjbUNzTQNzIwMlLSUTLTNzSEsQ0tjAwMlGJjAQ==", BinaryEncoding.Base64),
Compression.Deflate
)
),
let
_t = ((type nullable text) meta [Serialized.Text = true])
in
type table [#"Production Start" = _t, #"Production End" = _t, #"Production Qty" = _t]
),
#"Changed Type" = Table.TransformColumnTypes(
Source,
{{"Production Start", type date}, {"Production End", type date}, {"Production Qty", Int64.Type}},
"en-GB"
),
#"Invoked Custom Function" = Table.AddColumn(
#"Changed Type",
"Dates",
each fnDatesBetween([Production Start], [Production End], "Day")
),
#"Added Custom" = Table.AddColumn(#"Invoked Custom Function", "Divisor", each List.Count([Dates])),
#"Expanded Dates" = Table.ExpandListColumn(#"Added Custom", "Dates"),
#"Inserted Division" = Table.AddColumn(
#"Expanded Dates",
"DailyAmount",
each [Production Qty] / [Divisor],
type number
),
// I would stop here and load the data as it is into the data model to stay flexible. But if you are sure that you only want on monthly level, continue with the grouping.
#"Calculated Start of Month" = Table.TransformColumns(
#"Inserted Division",
{{"Dates", Date.StartOfMonth, type date}}
),
#"Grouped Rows" = Table.Group(
#"Calculated Start of Month",
{"Dates"},
{{"MonthlyAmount", each List.Sum([DailyAmount]), type number}}
)
in
#"Grouped Rows"
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 6 | |
| 5 |