Forum Discussion

gmasta1129's avatar
gmasta1129
Resolver I
9 months ago
Solved

Previous Day Balance - Excluding Weekends

Hello,   I am trying to create a formula to pull in the previous day balance for a certain portfolio code.    Please note, the report contains many portfolio codes, I am showing a sample of one c...
  • GeraldGEmerick's avatar
    9 months ago

    gmasta1129 I believe something like the following calculated column should work in DAX. In Power Query I feel like it would be more complex and you would have to create the previous day column and then join the table back to itself using that column and the original Run Date column and then expand the Today's Balance column. Somebody may have a more elegant solution.

    Previous Day Balance = 
    VAR _PortfolioCode = [Portfolio Code]
    VAR _RunDate = [Run Date]
    VAR _Weekday = WEEKDAY( [Run Date], 2 )
    VAR _PreviousDay = IF( _Weekday = 1, ( _RunDate - 3 ) * 1, ( _RunDate - 1 ) * 1 )
    VAR _PreviousBalance = FILTER( ALL( 'Table' ), [Portfolio Code] = _PortfolioCode && [Run Date] = _PreviousDay )
    VAR _Return = MAXX( _PreviousBalance, [Today's Balance] )
    RETURN _Return