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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
FrancisGhao
Frequent Visitor

Find last value within date range

Hi all,

I have trouble getting the appropiate value. I have 3 tables: date (), product and transactions. There is 1 to many link from date to product and transaction. 

 

Measure used: 

Prod Desc disregarding filter =
    VAR Currentprod = SELECTEDVALUE(TransactionTable[ProductID])
    RETURN
    MAXX(
        FILTER(ALL('ProductTable'), ProductTable[ProductID] =  Currentprod),
            ProductTable[Product Description])

Current Dax gives me the latest description (March) disregarding the filter selection Jan/Feb. I would like to see Jan description of product 1 when I select Jan and Feb Description of product 1 when I select Feb. 
If I select April, it would give me March (last available data)

 

FrancisGhao_0-1669711276814.png

Is there a dax formula that I should be using?

1 ACCEPTED SOLUTION

@FrancisGhao 
If you haven't shared the file, I wouldn't in a milion years figure out that in fact the Dates in the Product Table are in 2022 while the Dates in the Transaction Table are in 2018. The Dates in the Product Table do not even exist in the Date table! I was about to go crazy woundering why The Product Table do not exist inside the matrix even if the three months are were selected. 

Please refer to your sample file amended with the solution

1.png2.png

 

Prod Descr = 
VAR Currentprod =
    SELECTEDVALUE ('TransactionTable'[ProductID])
VAR T1 =
    CALCULATETABLE ( 
        ProductTable,
        ALL ( DateTable ),
        ProductTable[ProductID] = Currentprod,
        MONTH ( ProductTable[Date] ) <= MONTH ( MAX ( DateTable[Date] ) )
    )
VAR T2 =
    TOPN ( 1, T1, ProductTable[Date] )
VAR Result =
    MAXX ( T2, ProductTable[Product Description] )
RETURN
    Result

 

View solution in original post

6 REPLIES 6
FrancisGhao
Frequent Visitor

Thank you for the quick response. 
I copied the DAX, but it is not giving the desired result.
It is giving me the description of product 1 in Feb, but I lost the last available information of product 2 and 3. 

FrancisGhao_0-1669723708258.png

The desired result should be:

FrancisGhao_1-1669723977767.png

 

By the way, here is the link to the File. 

@FrancisGhao 
If you haven't shared the file, I wouldn't in a milion years figure out that in fact the Dates in the Product Table are in 2022 while the Dates in the Transaction Table are in 2018. The Dates in the Product Table do not even exist in the Date table! I was about to go crazy woundering why The Product Table do not exist inside the matrix even if the three months are were selected. 

Please refer to your sample file amended with the solution

1.png2.png

 

Prod Descr = 
VAR Currentprod =
    SELECTEDVALUE ('TransactionTable'[ProductID])
VAR T1 =
    CALCULATETABLE ( 
        ProductTable,
        ALL ( DateTable ),
        ProductTable[ProductID] = Currentprod,
        MONTH ( ProductTable[Date] ) <= MONTH ( MAX ( DateTable[Date] ) )
    )
VAR T2 =
    TOPN ( 1, T1, ProductTable[Date] )
VAR Result =
    MAXX ( T2, ProductTable[Product Description] )
RETURN
    Result

 

Sorry about the dates. I discovered the date after the initial upload and have reuploaded the file. But I was too late. 
Thank you for the solution. I have some excel background, but the transition to dax is not easy. Online tutorials and the https://learn.microsoft.com/ are a bit weak in the department of combining Dax funtions. 

@FrancisGhao 

If the dates are fixed then the first solution should work. 

Yes it is working now. I also marked "accept as solution" yesterday. 
FIrst post was a success :). Start of a new journey to get to know PowerBI. 

tamerj1
Super User
Super User

Hi @FrancisGhao 
Please try

Prod Desc =
VAR Currentprod =
    SELECTEDVALUE ( TransactionTable[ProductID] )
VAR T1 =
    FILTER ( ProductTable, ProductTable[ProductID] = Currentprod )
VAR T2 =
    TOPN ( 1, T1, ProductTable[Date] )
RETURN
    MAXX ( T2, ProductTable[Product Description] )

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.