Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
gmasta1129
Helper III
Helper III

Help with formula (measure)_Previous Day

Hello,

 

I am having an issue with a measure.

 

What I am looking to do is when the Run Date is equal to the Value Date, then pull in the previous day balance.  If there is no previous day balance then zero. 

 

This formula works but if there is no previous day balance (refer to the "Run Date column" to get the balance) then it finds the latest balance available. 

ex: if the run date is 11/1/2022 and the value date is 11/1/2022 then the balance from 10/31/2022 should pull in. In the screenshot below, the previous day balance that pulled in is from "Run Date" 10/24/2022 since there was no balance on 10/31/2022.  Please note, that when there is no balance then nothing pulls into the report.  Only balances that are less than 0 pull in the report. 

 

Also, this report runs Mon to Fri only so for example, Monday January 2nd , the formula should pull the balance for Friday December 30th since January 1st and December 31st are Saturday and Sunday. 

 

gmasta1129_0-1670566885255.png

 

List of Balances for October through December (refer to Run Date)

 

gmasta1129_1-1670567700818.png

 

 

 

Previous Day Balance =
VAR cur_rk = [RK]
VAR cur_flexacct =
SELECTEDVALUE ( 'over_draft'[flex_acct] )
VAR cur_cd =
SELECTEDVALUE ( 'over_draft'[If Value Date equal Run Date] )
VAR tmp =
FILTER (
ALL ( 'over_draft' ),
'over_draft'[flex_acct] = cur_flexacct
&& [RK] = cur_rk - 1
)
VAR _val =
CALCULATE ( MAX ( 'over_draft'[usd_balance] ), tmp )
RETURN
IF ( cur_cd = "N", 0, _val )

 

 

RK =
VAR cur_flexacct =
SELECTEDVALUE ( 'over_draft'[flex_acct] )
VAR tmp =
FILTER ( ALL ( 'over_draft' ), 'over_draft'[flex_acct] = cur_flexacct )
RETURN
RANKX ( tmp, CALCULATE ( MAX ( 'over_draft'[Run Date] ) ),, ASC, DENSE )

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.