Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Closing Balance Inventory Prior Year

Hi All, 

 

I am stuck on the following...

 

I am trying to create the Closing Balance Inventory for 2020 e compare with the same period last year..

 

Inventory SUM = (CALCULATE(SUM(Final[Value]),Final[Type] = "Inventory"))
Inventory 2020 = CLOSINGBALANCEQUARTER([Inventory SUM],Final[Date])
Inventory 19 = CALCULATE(CLOSINGBALANCEQUARTER([Inventory SUM],DATEADD(Final[Date],-1,YEAR)))
 
all works good but, when I am adding a slicer by Quarter, it tells me it expects a contigoous selection.
 
Any one has a clou on how I should fix it? 
 
 
thanks for the help.
Simone
  • Hi Anonymous 

     

    Does this return what you want?

    Inventory Last Year =
    CALCULATE(
        [Inv. Sum],
        SAMEPERIODLASTYEAR( 'Calendar'[Date] )
    )
    

    ALso, you need to mark your calendar table as a date table. That is when the magic happens. Right-click on it, select Mark as Date Table, then select the date column. Until you do that, it is just another table in the model.

9 Replies

  • edhans's avatar
    edhans
    Community Champion

    Hi Anonymous 

     

    Does this return what you want?

    Inventory Last Year =
    CALCULATE(
        [Inv. Sum],
        SAMEPERIODLASTYEAR( 'Calendar'[Date] )
    )
    

    ALso, you need to mark your calendar table as a date table. That is when the magic happens. Right-click on it, select Mark as Date Table, then select the date column. Until you do that, it is just another table in the model.

    • Anonymous's avatar
      Anonymous
      Not applicable

      thanks a lot for the answer. I need to use the closingbalancequarter.. 

       

      1. I marked the table as date

       

      but it still giving me a error... 

      • edhans's avatar
        edhans
        Community Champion

        I'm not an expert by any means on the CLOSINGBALANCE* functions, but I believe those return the data at the end of the relevant quarter, which would be March 31, June 30, Sept 30, and Dec 31. That works on your Calendar table.

         

        But those dates don't exist in your inventory table. Everything is the 1st of the month.

        My measure above returns the following:

        See this article near the bottom from SQLBI. It concludes the same thing I have. Emphasis mine.

         

        "The STARTOFMONTHSTARTOFQUARTERSTARTOFYEARENDOFMONTHENDOFQUARTER, and ENDOFYEAR functions are only useful when the dataset is complete with all the start and end dates of each time period. When this is not the case, you can implement a custom logic using the other techniques previously described in this article."

    • Anonymous's avatar
      Anonymous
      Not applicable

      man.. after 4 hours on this **bleep** formula... I got it!!!! thanks for the help. really killed me!!! appreciate!

      • edhans's avatar
        edhans
        Community Champion

        Anonymous wrote:

        man.. after 4 hours on this **bleep** formula... I got it!!!! thanks for the help. really killed me!!! appreciate!


        What was your final measure?

  • Anonymous do you have date dimension in your model? As a best practice, add date dimension in your model and use it for and time intelligence calculations. There are many posts on how to add date dimension and below is the link to a few. Once the date dimension is added, mark it as a date table on table tools.

    https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
    https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-1-calendar-columns

     

    If not, add one, and use that in your calculations.

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks, I have tried already, but it doesn't work

    • Anonymous's avatar
      Anonymous
      Not applicable

      hi, I have added the link to power BI, in case you want to have a look. thanks Simone