Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Calculation of inventory forecast coverage

Hi Everyone,   I was making a visualization model for forecasting analysis and one of the measure is forecast coverage for various items. Following is a sample data.   Item No On-hand Invento...
  • edhans's avatar
    5 years ago

    Anonymous you really need a date table for this.
    First I had to make some assumptions. The on hand was current month, then M+1 meant next month, M+2 meant 2 months from now, etc. Then I converted those to dates by unpivoting. Full code here:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjZU0lEyNDAAksYgwsRAKVYHKGwEZBtBhE1BwiZKsbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, OH = _t, #"M+1" = _t, #"M+2" = _t]),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"),
        #"Extracted Text After Delimiter" = Table.TransformColumns(#"Unpivoted Other Columns", {{"Attribute", each Text.AfterDelimiter(_, "+"), type text}}),
        #"Changed Type" = Table.TransformColumnTypes(#"Extracted Text After Delimiter",{{"Attribute", Int64.Type}, {"Value", Int64.Type}}),
        #"Added Date" = 
            Table.AddColumn(
                #"Changed Type", 
                "Date", 
                each 
                    Date.AddMonths(
                        Date.EndOfMonth(
                            DateTime.Date(
                                DateTime.LocalNow()
                                )
                            ), (if [Attribute] = null then 0 else [Attribute])
                    ),
                Date.Type
            ),
        #"Removed Other Columns" = Table.SelectColumns(#"Added Date",{"Item", "Date", "Value"})
    
    in
        #"Removed Other Columns"

    That turns this:

    into this:

    I couldn't use your original data. It was just one long string of text. See links below for putting data in usable tables.

    Then I added a date table to Power Query using this code, and changed the SOURCE line to be just Jan 1, 2021-Dec 31, 2021.

    Finally, by creating a few relatively simple measures, I was able to create a Table Visual that looks like this:

    Now we can count exact days in the month and do whatever you need. Rather than post those measures, just get my PBIX file here. It has everything in it.

     

    If you need further help, please provide good data and expected results per info here:

    How to get good help fast. Help us help you.
    How to Get Your Question Answered Quickly - Give us a good and concise explanation
    How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.