Forum Discussion

kostask's avatar
kostask
Helper II
4 years ago
Solved

Filling values for missing dates for many attribute combinations

Hi guys. I had the community's support for a similar problem, but the specific one seems more complicated for me to resolve. So, we have 3 attributes (Bank, CustomerNo, AccountNo), which give many ...
  • tamerj1's avatar
    4 years ago

    Hi kostask 
    Here is the updated solution with correct subtotals https://we.tl/t-ULVbpV6vB9

     

    FinalBalance1 = 
    VAR CurrentDate =
        MAX ( 'Calendar'[Date] )
    VAR IterationTable =
        CALCULATETABLE (
            SUMMARIZE ( 'Totals', 'Totals'[Bank], 'Totals'[Company], 'Totals'[AccountNo] ),
            ALL ( 'Calendar' )
        )
    RETURN
        SUMX (
            IterationTable,
            CALCULATE (
                VAR CurrentValue =
                    SUM ( 'Totals'[FinalBalance] )
                VAR CurrentAcountTable =
                    CALCULATETABLE ( 'Totals', ALL ('Calendar' ) )
                VAR PreviousDatesTable =
                    FILTER ( CurrentAcountTable, 'Totals'[Date] < CurrentDate )
                VAR PreviousDate =
                    MAXX ( PreviousDatesTable, 'Totals'[Date] )
                VAR PreviousDateTable =
                    FILTER ( PreviousDatesTable, 'Totals'[Date] = PreviousDate )
                VAR PreviousValue =
                    SUMX ( PreviousDateTable, 'Totals'[FinalBalance] )
                RETURN
                    - COALESCE ( CurrentValue, PreviousValue )
            )
        )