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
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
Super User
Super User

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
Super User
Super User

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
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.

Top Solution Authors