Forum Discussion

avinash2807's avatar
avinash2807
Regular Visitor
4 years ago
Solved

Calculate Closing Balance for Week in Every Month

I want to calculate closing balance of week ,  I have two tables one sales table with sales on each day and another calendar table with each day , week number, and week range    Sales Table  Cale...
  • Jihwan_Kim's avatar
    4 years ago

    Hi,

    Please check the below picture and the attached pbix file.

     

     

    lastnonblankdate = 
    LASTNONBLANK ( Sales[CalendarDate], CALCULATE ( SUM ( Sales[QtyAvailable] ) ) )

     

    lastnonblankvaue by category: =
    VAR _lastnonblankdatebycategory =
        ADDCOLUMNS (
            SUMMARIZE ( Sales, Category[Category] ),
            "@lastnonblankdate", [lastnonblankdate]
        )
    RETURN
        IF (
            HASONEVALUE ( CalendarTable[WeekRange] ),
            CALCULATE (
                SUM ( Sales[QtyAvailable] ),
                TREATAS (
                    _lastnonblankdatebycategory,
                    Category[Category],
                    CalendarTable[CalendarDate]
                )
            )
        )