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
rwamorim
Frequent Visitor

need to fill gaps based on past cost

I need to create a graph of the cost of my inventory based on item movement, however, there are items that are not moved in the month, so I need a formula that does that. The idea is to put this on a line graph that will show if my inventory cost is growing or not.

 

Example:
I had movement of item x in March/21 leaving my inventory at 500. The other movement was in July/21 which left my inventory at 100. From April/21 to June/21 the function has to copy these 500 so that I don't have gaps.

In the table I have the columns: competence, product code, product, unit, stock and the cost of stock in the competition.

 

unfortunately I don't know how to do this :~(

 

I'm sharing the database looking for help.

 

https://docs.google.com/spreadsheets/d/1FI21etPCE1guDCjHPxRzlTxxVS6Z4m2m/edit?usp=sharing&ouid=10382... 

 

 

 

 

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

Hi @rwamorim ,

 

Need to transform table in powerquery to determine the conditions to filter out the day of the month. It will automatically fill the month where the stock field has not changed. Finally the results are presented in powerbi desktop, refer to the following.

vstephenmsft_0-1638781890262.png

let
    Source = Excel.Workbook(File.Contents("need to fill gaps based on past cost.xlsx"), null, true),
    Planilha1_Sheet = Source{[Item="Planilha1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Planilha1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"competence", type date}, {"product code", Int64.Type}, {"product", type text}, {"unit", type text}, {"stock", Int64.Type}, {"cost of stock", type number}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"competence", Order.Ascending}}),
    #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each ([competence] <> null)),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Date", each { Number.From([competence])..Number.From([competence]) }),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"product code", "product", "unit", "cost of stock", "Date"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns", "Custom", each Table.Max(Planilha1,"competence")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom1", "Custom", {"competence"}, {"Custom.competence"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom.competence", "Max_date"}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"Max_date", type date}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type2", "Custom", each {Number.From([competence])..Number.From([Max_date])}),
    #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom2", "Custom"),
    #"Changed Type3" = Table.TransformColumnTypes(#"Expanded Custom1",{{"Custom", type date}}),
    #"Added Custom3" = Table.AddColumn(#"Changed Type3", "Custom.1", each if Date.Day([Custom])=1 then 1 else 0),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom3", each ([Custom.1] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows1",{"Max_date", "Custom.1"})
in
    #"Removed Columns1"

vstephenmsft_1-1638781950164.png

 

If the problem is still not resolved, please point it out. Looking forward to your feedback.


Best Regards,
Stephen


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

View solution in original post

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @rwamorim ,

 

Need to transform table in powerquery to determine the conditions to filter out the day of the month. It will automatically fill the month where the stock field has not changed. Finally the results are presented in powerbi desktop, refer to the following.

vstephenmsft_0-1638781890262.png

let
    Source = Excel.Workbook(File.Contents("need to fill gaps based on past cost.xlsx"), null, true),
    Planilha1_Sheet = Source{[Item="Planilha1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Planilha1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"competence", type date}, {"product code", Int64.Type}, {"product", type text}, {"unit", type text}, {"stock", Int64.Type}, {"cost of stock", type number}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"competence", Order.Ascending}}),
    #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each ([competence] <> null)),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Date", each { Number.From([competence])..Number.From([competence]) }),
    #"Expanded Date" = Table.ExpandListColumn(#"Added Custom", "Date"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Date",{{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"product code", "product", "unit", "cost of stock", "Date"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Columns", "Custom", each Table.Max(Planilha1,"competence")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom1", "Custom", {"competence"}, {"Custom.competence"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Custom.competence", "Max_date"}}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Renamed Columns",{{"Max_date", type date}}),
    #"Added Custom2" = Table.AddColumn(#"Changed Type2", "Custom", each {Number.From([competence])..Number.From([Max_date])}),
    #"Expanded Custom1" = Table.ExpandListColumn(#"Added Custom2", "Custom"),
    #"Changed Type3" = Table.TransformColumnTypes(#"Expanded Custom1",{{"Custom", type date}}),
    #"Added Custom3" = Table.AddColumn(#"Changed Type3", "Custom.1", each if Date.Day([Custom])=1 then 1 else 0),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom3", each ([Custom.1] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows1",{"Max_date", "Custom.1"})
in
    #"Removed Columns1"

vstephenmsft_1-1638781950164.png

 

If the problem is still not resolved, please point it out. Looking forward to your feedback.


Best Regards,
Stephen


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

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.