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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ConnieMaldonado
Responsive Resident
Responsive Resident

Find first non-zero value in calculate statement

I am trying to create a measure that will pick up the first non zero entry for a specific week.

 

DateValue
3/14/2023    0
3/13/2023    32
3/12/2023    0
3/11/2023    45
3/10/2023    28
3/9/202365
3/8/202343

 

For today (3/14/23), the value would be 32 since today's value is 0.

If 3/13/23 was also 0, it would pick up 45 and so on until it finds the first non-zero value.

I wound up creating the logic using variables and if statements, but I know there's a cleaner way to do it.

 

Var _Value =
    CALCULATE(
        SUM('Table'[Value]),
        FILTER('Table', 'Table'[DATE] = TODAY())
    )
 
Is there any way to integrate the logic into the calculate statement above?
1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @ConnieMaldonado 

According to your description, you want to "pick up the first non zero entry for a specific week.".

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can create a measure like this:

Measure = var _cur_value =   SUM('Table'[Value])
var _cur_date = MAX('Table'[Date])
var _t =FILTER( SUMMARIZE(ALLSELECTED('Table'),'Table'[Date] , "value", SUM('Table'[Value])) , [Date]<_cur_date && [value] <>0)
var _max_date =  MAXX(_t,[Date])
var _t2= FILTER(_t,[Date]=_max_date)
return
IF(_cur_value=0 , MAXX(_t2,[value]),_cur_value )

(3)Then we can put the measure on the visual and the result is as follows:

vyueyunzhmsft_0-1678931455954.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
ConnieMaldonado
Responsive Resident
Responsive Resident

Thank you!  That worked.  I appreciate it.

v-yueyunzh-msft
Community Support
Community Support

Hi , @ConnieMaldonado 

According to your description, you want to "pick up the first non zero entry for a specific week.".

Here are the steps you can refer to :
(1)My test data is the same as yours.

(2)We can create a measure like this:

Measure = var _cur_value =   SUM('Table'[Value])
var _cur_date = MAX('Table'[Date])
var _t =FILTER( SUMMARIZE(ALLSELECTED('Table'),'Table'[Date] , "value", SUM('Table'[Value])) , [Date]<_cur_date && [value] <>0)
var _max_date =  MAXX(_t,[Date])
var _t2= FILTER(_t,[Date]=_max_date)
return
IF(_cur_value=0 , MAXX(_t2,[value]),_cur_value )

(3)Then we can put the measure on the visual and the result is as follows:

vyueyunzhmsft_0-1678931455954.png

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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