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
Crydus
Helper I
Helper I

Return last Sales if current Sales are 0

Hey, 

 

I have a problem within Power BI. 

I have a list of sales per month and in some months there are no sales. Now I want to display the last value where the sales have been >0, but i don't know how to do this. 

Here is a small example for you to illustrate the problem. 

Thanks in advance!!

Test.PNG

1 ACCEPTED SOLUTION
sokg
Solution Supplier
Solution Supplier

Hi @Crydus 

 

First create a measure

SumOfSales = SUM(Table1[sales])
and a second measure
 
SalesNew =
VAR CurrentDate =
MAX ( Table1[datum] )
VAR maxDateWithSales =
CALCULATE (
MAX ( Table1[datum] );
FILTER (
ALL ( Table1[datum] );
[SumOfSales] > 0
&& Table1[datum] <= CurrentDate
)
)
RETURN
CALCULATE (
[SumOfSales];
FILTER ( ALL ( Table1[datum] ); Table1[datum] = maxDateWithSales )
)
 
the result is
 
Capture1.JPG

View solution in original post

5 REPLIES 5
sokg
Solution Supplier
Solution Supplier

Hi @Crydus 

 

First create a measure

SumOfSales = SUM(Table1[sales])
and a second measure
 
SalesNew =
VAR CurrentDate =
MAX ( Table1[datum] )
VAR maxDateWithSales =
CALCULATE (
MAX ( Table1[datum] );
FILTER (
ALL ( Table1[datum] );
[SumOfSales] > 0
&& Table1[datum] <= CurrentDate
)
)
RETURN
CALCULATE (
[SumOfSales];
FILTER ( ALL ( Table1[datum] ); Table1[datum] = maxDateWithSales )
)
 
the result is
 
Capture1.JPG

Thank you so much. 

I'm fairly new to PBI and the FILTER expressions are still very confusing to me. But this works as intended 🙂 

 

Again, many, many thanks. 

sokg
Solution Supplier
Solution Supplier

Glad to help you!!!

Omega
Impactful Individual
Impactful Individual

Try the below measure: 

 

Measure = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Date]=MAX('Table'[Date]) && SUM('Table'[Sales])>0))

Thanks for your suggestion, unfortunately this didn't bring me the expected result 😞 

 

My goal is to have a column where no row is equal to 0, i.e. if February has no sales, I want to have the sales of january and in August the Sales of may should be visible. 

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.