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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
CheanSereyvatan
Frequent Visitor

Dear Sirs,

I try to calculate the last sale record of each customer and product with the date rank. let say now we stand on 25/Mar/2024. I want to calculate the last sale record of each customer and product during 5 days back. 

Please see the below sample. Thanks

CheanSereyvatan_0-1711362828963.png

 

2 ACCEPTED SOLUTIONS
CheanSereyvatan
Frequent Visitor

Dear Albert He,
It nearly to the point. How to add date rank in to the calculation? I dont want to calculate the whole transaction as we have 5 years data with 6 millions record already. Here I want it to calculate back 15 day till now. For example, now we are 26-Mar-2024. I want to calculate the last sale record from 11-Mar-2024 to 26-Mar-2024. 
Best Regards,

Vatanak

View solution in original post

Hi @CheanSereyvatan ,
Depending on your requirements, you can try the following methods
1.Create a new date table based on Table[Date].

Date = VALUES('Table'[Date])

2.Create a slicer accroding to Date[Date]
3.Modified measure

Last Sale Record = 
VAR _RES =
CALCULATE(
    MAX('Table'[Date]),
    FILTER(
        ALLEXCEPT('Table', 'Table'[Customer ID], 'Table'[Product Name]),
        DATEDIFF('Table'[Date],SELECTEDVALUE('Date'[Date]),DAY) >= 1
    )
)
RETURN
IF(
    SELECTEDVALUE('Table'[Date]) = _RES,
    1,
    0
)

Final output
The table on the right is the initial table after filtering by date range, i.e. before grouping by id and product.

vheqmsft_0-1711440989689.png

If you want to modify the filtering time range, you can modify the parameter after datediff.

Best regards,

Albert He

 

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

4 REPLIES 4
CheanSereyvatan
Frequent Visitor

Dear Albert He,
It nearly to the point. How to add date rank in to the calculation? I dont want to calculate the whole transaction as we have 5 years data with 6 millions record already. Here I want it to calculate back 15 day till now. For example, now we are 26-Mar-2024. I want to calculate the last sale record from 11-Mar-2024 to 26-Mar-2024. 
Best Regards,

Vatanak

Hi @CheanSereyvatan ,
Depending on your requirements, you can try the following methods
1.Create a new date table based on Table[Date].

Date = VALUES('Table'[Date])

2.Create a slicer accroding to Date[Date]
3.Modified measure

Last Sale Record = 
VAR _RES =
CALCULATE(
    MAX('Table'[Date]),
    FILTER(
        ALLEXCEPT('Table', 'Table'[Customer ID], 'Table'[Product Name]),
        DATEDIFF('Table'[Date],SELECTEDVALUE('Date'[Date]),DAY) >= 1
    )
)
RETURN
IF(
    SELECTEDVALUE('Table'[Date]) = _RES,
    1,
    0
)

Final output
The table on the right is the initial table after filtering by date range, i.e. before grouping by id and product.

vheqmsft_0-1711440989689.png

If you want to modify the filtering time range, you can modify the parameter after datediff.

Best regards,

Albert He

 

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



Dear Albert He,

Thanks for your idea. It's realy greate. On top of this, It only work when we put all data in like date, customer ID, Product name,...... but it doesn't work when I want to show only the qty of last sale date. Can you share if there is another way to calculate this? Thanks

 

v-heq-msft
Community Support
Community Support

Hi @CheanSereyvatan ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1711416565015.png

Create a measure

 

Last Sale Record = 
VAR _RES =
CALCULATE(
    MAX('Table'[Date]),
    ALLEXCEPT('Table', 'Table'[Customer ID], 'Table'[Product Name])
)
RETURN
IF(
    SELECTEDVALUE('Table'[Date]) = _RES,
    1,
    0
)

 

Apply the measure to the filter on this vixual

vheqmsft_2-1711416754841.png

 

Best regards,

Albert He

 

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.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.