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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Chimsie
Helper III
Helper III

How to extent LASTNONBLANK formula with SUM

All,

 

I need help with a LASTNONBLANK formula, I want the output of the formula to sum the value from the column "Predicted Value"

in the column LASTNONBLANK

The formula:

LASTNONBLANK = 
var CA = [CA]
var curDate = [Date]
var priorMaxDate = CALCULATE(MAX('AssetRealtimeDataLog'[Date]), FILTER('AssetRealtimeDataLog', 'AssetRealtimeDataLog'[CA] = CA && [Date] < curDate && 'AssetRealtimeDataLog'[Value] <> BLANK()))
return
if([Value] = blank(), CALCULATE(max('AssetRealtimeDataLog'[Value]), FILTER('AssetRealtimeDataLog', [CA] = CA && [Date] = priorMaxDate)), 'AssetRealtimeDataLog'[Value])

 

Example:
Capture.PNG

Thanks!

 

1 ACCEPTED SOLUTION

Hi @Chimsie ,

 

See if this will meet your needs:

V-lianl-msft_0-1606721702250.png

LASTNONBLANK = 
var CA = [CA]
var curDate = [Date] 
var priorMaxDate = CALCULATE(MAX('AssetRealtimeDataLog'[Date]), FILTER('AssetRealtimeDataLog', 'AssetRealtimeDataLog'[CA] = CA && [Date] < curDate && 'AssetRealtimeDataLog'[Value] <> BLANK())) 
var sum_pv = SUMX(FILTER(AssetRealtimeDataLog,AssetRealtimeDataLog[CA]=CA&&AssetRealtimeDataLog[DATE]<=curDate),AssetRealtimeDataLog[PREDICTED VALUE])
return 
if([Value] = blank(), sum_pv+CALCULATE(max('AssetRealtimeDataLog'[Value]), FILTER('AssetRealtimeDataLog', [CA] = CA && [Date] = priorMaxDate)), 'AssetRealtimeDataLog'[Value])

V-lianl-msft_1-1606721751990.png

Add a cumulative value of [PREDICTED VALUE] column before the return value.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Chimsie
Helper III
Helper III

 

 

Input

Input

Input

Calc

Input

Expected Result

Date

CA

Value

LASTNONBLANK

Predicted value

RESULT

Wednesday, November 25, 2020

CA111

66.804

66.804

 

66.804

Wednesday, November 25, 2020

CA999

37.449

37.449

 

37.449

Thursday, November 26, 2020

CA111

65.852

65.852

 

65.852

Thursday, November 26, 2020

CA999

37.434

37.434

 

37.434

Friday, November 27, 2020

CA111

64.38

64.38

 

64.38

Friday, November 27, 2020

CA999

37.126

37.126

 

37.126

Saturday, November 28, 2020

 

 

 

 

 

Sunday, November 29, 2020

 

 

 

 

 

Monday, November 30, 2020

 

 

 

 

 

Tuesday, December 1, 2020

CA111

 

64.38

20

84.38

Tuesday, December 1, 2020

CA999

 

37.126

30

67.126

Wednesday, December 2, 2020

 

 

 

 

 

Thursday, December 3, 2020

 

 

 

 

 

Friday, December 4, 2020

 

 

 

 

 

Saturday, December 5, 2020

CA111

 

64.38

30

114.38

Sunday, December 6, 2020

 

 

 

 

 

Monday, December 7, 2020

 

 

 

 

 

Tuesday, December 8, 2020

 

 

 

 

 

Wednesday, December 9, 2020

 

 

 

 

 

Thursday, December 10, 2020

CA111

 

64.38

10

124.38

Thursday, December 27, 2020

CA999

 

37.126

20

104.38

 

 

amitchandak
Super User
Super User

@Chimsie ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak see attached sample data, the Column LASTNONBLANK is based on the formula above, the RESULT column is the result where I'm looking for, preferably in the Column LASTNONBLANK.

The RESULT column is the LASTNONBLANK and Predicted Value Added (SUM) column together and used as input as for the next LASTNONBLANK. I hope it makes sense what I'm asking.


I was not able to past a table in to the message, the system keeps complaining about  a HTML error in the message header, is a picture also oke?

Chimsie_0-1606515713514.png

 

Hi @Chimsie ,

 

See if this will meet your needs:

V-lianl-msft_0-1606721702250.png

LASTNONBLANK = 
var CA = [CA]
var curDate = [Date] 
var priorMaxDate = CALCULATE(MAX('AssetRealtimeDataLog'[Date]), FILTER('AssetRealtimeDataLog', 'AssetRealtimeDataLog'[CA] = CA && [Date] < curDate && 'AssetRealtimeDataLog'[Value] <> BLANK())) 
var sum_pv = SUMX(FILTER(AssetRealtimeDataLog,AssetRealtimeDataLog[CA]=CA&&AssetRealtimeDataLog[DATE]<=curDate),AssetRealtimeDataLog[PREDICTED VALUE])
return 
if([Value] = blank(), sum_pv+CALCULATE(max('AssetRealtimeDataLog'[Value]), FILTER('AssetRealtimeDataLog', [CA] = CA && [Date] = priorMaxDate)), 'AssetRealtimeDataLog'[Value])

V-lianl-msft_1-1606721751990.png

Add a cumulative value of [PREDICTED VALUE] column before the return value.

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@V-lianl-msft Thank You very much, this solved my issue:-)

Hi,

See if the article here helps - LASTNONBLANK Explained - Excelerator BI


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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