Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Summarizing data between two dates and filtered by location and invoice category

I'm looking to sum invoices between two dates and filtered by location. One location (battery) could pull in anywhere between 1 and 20 individual datasets (wells). The invoices also have different categories. I've included samples of the tables I have and an example of what I want to get out of it.

 

All of the data has the necessary relationships (linked by Well ID#). And I have a Date Table w/ relationship to everything else.

 

Well names/ID and the Battery they go to:

 

WellWell ID#Battery
Well 11111Battery 1
Well 22222Battery 1
Well 33333Battery 1
Well 44444Battery 1
Well 55555Battery 2
Well 66666Battery 2
Well 77777Battery 3
Well 88888Battery 3
Well 99999Battery 4

 

Battery name, the start date and end dates (start date + 180 days):

 

BatteryStart DateEnd Date
Battery 11/1/20246/29/2024
Battery 22/1/20247/30/2024
Battery 33/1/20248/28/2024
Battery 44/1/20249/28/2024

 

Invoices for each well:

 

WellWell ID#Cost CategoryInvoice Amt
Well 11111Surface100
Well 11111Surface200
Well 11111Downhole300
Well 22222Surface150
Well 22222Surface500
Well 22222Downhole300
Well 22222Downhole400
Well 22222Downhole100

 

Deliverable:

 

BatteryStart DateSurface CostsDownhole Costs
Battery 11/1/2024300300
Battery 22/1/2024650800
Battery 33/1/2024  
Battery 44/1/2024  

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Anonymous ,

    Based on the information you have provided, there seems to be some food for thought about your expected results.
    Your Well 1 and Well 2 both correspond to Battery 1 , whereas the final desired result contains a Battery 2 classification. Anyway hopefully the following steps will help:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bckrDsAgFETRrTRoDH+w3UQFQVTgUA2mu+8VTUC8ayaZU6u6+hiHUVoZYs57zv68XE3/arktyeq4HcnquT3JGrgDbWqXRu5IsibuRJu6pZk7k6yFu9CmXrX2AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Well = _t, #"Well ID#" = _t, Battery = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Well", type text}, {"Well ID#", Int64.Type}, {"Battery", type text}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Well"}, Well_CostCategory, {"Well"}, "Well_CostCategory", JoinKind.LeftOuter),
        #"Expanded Well_CostCategory" = Table.ExpandTableColumn(#"Merged Queries", "Well_CostCategory", {"Cost Category", "Invoice Amt"}, {"Well_CostCategory.Cost Category", "Well_CostCategory.Invoice Amt"}),
        #"Merged Queries1" = Table.NestedJoin(#"Expanded Well_CostCategory", {"Battery"}, Battery_Date, {"Battery"}, "Battery_Date", JoinKind.LeftOuter),
        #"Expanded Battery_Date" = Table.ExpandTableColumn(#"Merged Queries1", "Battery_Date", {"Battery", "Start Date"}, {"Battery_Date.Battery", "Battery_Date.Start Date"})
    in
        #"Expanded Battery_Date"

     

    Fianl output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Also, each invoice will have a date associated with them. I forgot to include that.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Based on the information you have provided, there seems to be some food for thought about your expected results.
    Your Well 1 and Well 2 both correspond to Battery 1 , whereas the final desired result contains a Battery 2 classification. Anyway hopefully the following steps will help:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bckrDsAgFETRrTRoDH+w3UQFQVTgUA2mu+8VTUC8ayaZU6u6+hiHUVoZYs57zv68XE3/arktyeq4HcnquT3JGrgDbWqXRu5IsibuRJu6pZk7k6yFu9CmXrX2AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Well = _t, #"Well ID#" = _t, Battery = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Well", type text}, {"Well ID#", Int64.Type}, {"Battery", type text}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Well"}, Well_CostCategory, {"Well"}, "Well_CostCategory", JoinKind.LeftOuter),
        #"Expanded Well_CostCategory" = Table.ExpandTableColumn(#"Merged Queries", "Well_CostCategory", {"Cost Category", "Invoice Amt"}, {"Well_CostCategory.Cost Category", "Well_CostCategory.Invoice Amt"}),
        #"Merged Queries1" = Table.NestedJoin(#"Expanded Well_CostCategory", {"Battery"}, Battery_Date, {"Battery"}, "Battery_Date", JoinKind.LeftOuter),
        #"Expanded Battery_Date" = Table.ExpandTableColumn(#"Merged Queries1", "Battery_Date", {"Battery", "Start Date"}, {"Battery_Date.Battery", "Battery_Date.Start Date"})
    in
        #"Expanded Battery_Date"

     

    Fianl output:

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.