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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Fathopes
Frequent Visitor

Return Previos Collection Date and Value

Hi All,

 

I have one table below consist of Trips of outlet with collection. I would like to return the table like below where the trip have zero collection as per my applied filter is 0 for total KG collected. Based on the table below, I would like to return the previos date collection, previous qty collected and days in between. This will be very helpful for me if there is any dax formula that able return below data

 

Trips of Outlet with Collection

 Collection DateOUTLET NAMETotal KG Collected
22/5/2021 0:00BAMBOO GARDEN80.19
18/6/2021 0:00BAMBOO GARDEN0
19/7/2021 0:00BAMBOO GARDEN0
20/8/2021 0:00BAMBOO GARDEN0
16/6/2021 0:0021 SEAFOOD17
8/7/2021 0:0021 SEAFOOD0
23/7/2021 0:0021 SEAFOOD0
2/9/2021 0:0021 SEAFOOD0
30/9/2021 0:0021 SEAFOOD34
14/10/2021 0:0021 SEAFOOD0

 

the trip have zero collection

Zero Collection DateOUTLET NAMETotal KG CollectedPrevious Collection DatePrevious Quantity CollectedDays Between Previous Collection and Current Zero Collection
2/9/2021 0:0021 SEAFOOD0   
14/10/2021 0:0021 SEAFOOD0   
8/7/2021 0:0021 SEAFOOD0   
23/7/2021 0:0021 SEAFOOD0   
18/6/2021 0:00BAMBOO GARDEN0   
19/7/2021 0:00BAMBOO GARDEN0   
20/8/2021 0:00BAMBOO GARDEN0   

 

Thanks and Regards,

Hopes

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hi @Fathopes ,

You can use the measures below:

Total 0 KG Collected =
CALCULATE ( SUM ( T[Total KG Collected] ), T[Total KG Collected] = 0 )
Previous Collection Date =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
RETURN
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
Previous Quantity Collected =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
VAR prevDate =
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
RETURN
    CALCULATE ( MAX ( T[Total KG Collected] ), T[Collection Date] = prevDate )
Days Between =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
VAR prevDate =
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
RETURN
    DATEDIFF ( prevDate, currentDate, DAY )

ERD_0-1634915309166.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

2 REPLIES 2
ERD
Community Champion
Community Champion

Hi @Fathopes ,

You can use the measures below:

Total 0 KG Collected =
CALCULATE ( SUM ( T[Total KG Collected] ), T[Total KG Collected] = 0 )
Previous Collection Date =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
RETURN
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
Previous Quantity Collected =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
VAR prevDate =
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
RETURN
    CALCULATE ( MAX ( T[Total KG Collected] ), T[Collection Date] = prevDate )
Days Between =
VAR currentDate = SELECTEDVALUE ( T[Collection Date] )
VAR prevDate =
    CALCULATE (
        MAX ( T[Collection Date] ),
        T[Collection Date] < currentDate,
        T[Total KG Collected] <> 0
    )
RETURN
    DATEDIFF ( prevDate, currentDate, DAY )

ERD_0-1634915309166.png

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Fathopes
Frequent Visitor

Thank You So Much...Its working

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.