Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Generating data when there is no sale

Hello everyone,

 

I'm working with a model that contains information about sales of different products in different centers. The fact table of sales contains data only for the days that a product has been sold in a center, which means that I have no info if a product has not been sold in a day. I need to "physically" have data for every day that this happens, so instead of not having a row, I would have a row containing the information of that day, the center, the product and quantity 0. 

 

I know I can use "Show items with no data" in the visual object, but that's not what I'm looking for since I need to have the rows in the table. 

 

An example of what I'm saying is this:

 

Current info:

Date (dd/mm/yyyy)CenterProductQty
01/01/2020AP115
01/01/2020AP27
02/01/2020AP19
03/01/2020AP110
03/01/2020AP26

 

Desired info:

Date (dd/mm/yyyy)CenterProductQty
01/01/2020AP115
01/01/2020AP27
02/01/2020AP19
02/01/2020AP20
03/01/2020AP110
03/01/2020AP26

 

As you can see, I added info with Qty 0 for the Center "A", Product "P2" on day "02/01/2020". This is what I'm trying to automatically add.

 

Do you guys know how can I make this in PBI?

 

Thank you in advance.

  • This can be done in the query editor as follows.

     

    Create a list of dates with List.Dates spanning the range you need and convert it to a table

    Add a column with a table of your Product and Centers, and expand it

    At this point you'll have a row for every combinations of Date and Product/Center

    Merge your actual data table into this new table on Date and Product columns

    Expand the merged table

    Replace nulls (rows that didn't have a match) with zeros

     

    Regards,

    Pat

     

11 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Anonymous ,

       

      Thank you for your reply. I know I can do that, but that's not a valid solution since, as I said, I need to physically have those rows in my dataset. Your solution generates those rows for the visual object where you are using it but they don't exist in the dataset below.

       

       

  • Anonymous , You can add +0 to the measure

    like sum(Table[Qty]) +0

     

    or use this option - Show Item with No data

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello amitchandak ,

       

      Thank you for your reply. As I said, I know I can use the "show items with no data" option, but it's not what I'm looking for. I'm actually trying to generate the rows in the dataset, so I have physical rows for every day that has no sale.

       

       

      • PaulDBrown's avatar
        PaulDBrown
        Icon for Community Champion rankCommunity Champion

        Anonymous 

         

        Both the methods suggested by Anonymous @  and amitchandak work, but you need to use a date table  with continuous dates covering the range of dates in your fact table (not the date from your fact table)  in your visual.

        Here is the model as I have it, and highlighted in red are the dimension tables I've used to create the table visual. The measures are according to Anonymous  and amitchandak  suggestions:

         

         

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    This can be done in the query editor as follows.

     

    Create a list of dates with List.Dates spanning the range you need and convert it to a table

    Add a column with a table of your Product and Centers, and expand it

    At this point you'll have a row for every combinations of Date and Product/Center

    Merge your actual data table into this new table on Date and Product columns

    Expand the merged table

    Replace nulls (rows that didn't have a match) with zeros

     

    Regards,

    Pat

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you very much mahoneypat , that was it 🙂 

       

      Kind regards