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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Filter out consecutive null values

Hello,

 

How can I create a slicer(or other means) to ignore Products which have not been sold consecutively in the last three days ?            

 

I have the following table:

johnray_0-1623834263532.png

 

 

Then I needed an output table that ONLY adds the number of units sold of products which have not been zero in the last three days

 

Output table:

johnray_1-1623834278777.png

 

Thanks,

John

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

You can try the following formula:

Sales in the last 3 days =
VAR saleslast3days =
    CALCULATE (
        SUM ( Sales[Units Sold] ),
        DATESBETWEEN ( Sales[Date], MAX ( Sales[Date] ) - 2, MAX ( Sales[Date] ) )
    )
RETURN
    IF ( saleslast3days > 0, saleslast3days )

 

And the result is below:

MFelix_0-1623919486216.png

If you want this to be dinamic based on a selection of dates you need to have a disconnected table for the filtering and then redo your measure using that table:

 

Sales in the last 3 days = 
VAR saleslast3days =
    CALCULATE (
        SUM ( Sales[Units Sold] ),
        DATESBETWEEN ( Sales[Date], MAX ( Dates[Date] ) - 2, MAX ( Dates[Date] ) )
    )
RETURN
    IF ( saleslast3days > 0, saleslast3days )

MFelix_1-1623919561243.png

 

Check PBIX file with both options.

MFelix_2-1623919625053.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

6 REPLIES 6
MFelix
Super User
Super User

Hi @Anonymous ,

 

You can try the following formula:

Sales in the last 3 days =
VAR saleslast3days =
    CALCULATE (
        SUM ( Sales[Units Sold] ),
        DATESBETWEEN ( Sales[Date], MAX ( Sales[Date] ) - 2, MAX ( Sales[Date] ) )
    )
RETURN
    IF ( saleslast3days > 0, saleslast3days )

 

And the result is below:

MFelix_0-1623919486216.png

If you want this to be dinamic based on a selection of dates you need to have a disconnected table for the filtering and then redo your measure using that table:

 

Sales in the last 3 days = 
VAR saleslast3days =
    CALCULATE (
        SUM ( Sales[Units Sold] ),
        DATESBETWEEN ( Sales[Date], MAX ( Dates[Date] ) - 2, MAX ( Dates[Date] ) )
    )
RETURN
    IF ( saleslast3days > 0, saleslast3days )

MFelix_1-1623919561243.png

 

Check PBIX file with both options.

MFelix_2-1623919625053.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

Hi @MFelix ,

 

I have another question, which is almost like an extension of this problem. Just out of courtesy, would you mind if I tag you into it if I post it as a separate community question?

No problem.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Anonymous
Not applicable

Anonymous
Not applicable

Hi @MFelix

 

Could you please clarify on what you meant by

 

"if you want this to be dinamic based on a selection of dates you need to have a disconnected table for the filtering and then redo your measure using that table"

 

what table do i need to create for this? 

Hi @Anonymous 

 

sorry wrote faster than I think about the phrase. If you check my PBIX file I have a table with only dates.

 

You need to create a date table with all the dates and used it has your slicer.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.