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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Jonete
Frequent Visitor

DAX Last Date - Other field

Hello:

 

I need help with an issue i’m not able to solve by myself.

 

I’m working on a model about storage. I have an article table and a movements table.  An article migth be moved from one store to another, and i woul like to get the store of the last movement for each article.

 

To get that, I´m creating a table:

CALCULATETABLE (
    SELECTCOLUMNS (
        ADDCOLUMNS (
            CALCULATETABLE (
                IFMSAL_ARTICLES,
                SUMMARIZECOLUMNS ( IFMSAL_MOVEMENTS [Article] )
            ),
            "Date",Calculate(Max(IFMSAL_ MOVEMENTS [MovementDate])),
            "Store", CALCULATE ( MAX ( IFMSAL_ MOVEMENTS [MovementStore] ) )
           
        ),
        "articulo", IFMSAL_ ARTICLES [Article],
        "Store",[Store],
        "Date",[Date]
        
    )
)

But I know it’s not right because what i get is the maximun store number not the store of the las movement.

 

Any help would be appreciated.

 

The model looks like this:

 

Movements table:

DateArticleStore
01/01/2018Article 1Store A
02/01/2018Article 2Store A
03/01/2018Article 3Store A
04/01/2018Article 4Store A
05/01/2018Article 1Store A
06/01/2018Article 1Store B
07/01/2018Article 2Store A
08/01/2018Article 3Store B

 

 

Articles table:

ArticleDescription
Article 1Article Description 1
Article 2Article Description 2
Article 3Article Description 3
Article 4Article Description 4

 

 

And what i would like to obtain is:

 

 

ArticleStore
Article 1Store B
Article 2Store A
Article 3Store A
Article 4Store B
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jonete,

 

You can try to use below measure to get last store group by article.

LastStore =
VAR temp =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, [Article], "LastDate", MAX ( [Date] ) ),
        "Store", LOOKUPVALUE (
            Table1[Store],
            Table1[Article], [Article],
            Table1[Date], [LastDate]
        )
    )
RETURN
    MAXX ( FILTER ( temp, [Article] = SELECTEDVALUE ( Table1[Article] ) ), [Store] )

11.PNG

 

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Jonete,

 

You can try to use below measure to get last store group by article.

LastStore =
VAR temp =
    ADDCOLUMNS (
        SUMMARIZE ( Table1, [Article], "LastDate", MAX ( [Date] ) ),
        "Store", LOOKUPVALUE (
            Table1[Store],
            Table1[Article], [Article],
            Table1[Date], [LastDate]
        )
    )
RETURN
    MAXX ( FILTER ( temp, [Article] = SELECTEDVALUE ( Table1[Article] ) ), [Store] )

11.PNG

 

Regards,

Xiaoxin Sheng

Hi @Anonymous,

 

 

I have tried your code in power BI with the given examples from the main question. However it does not seem to work. I have changed the code by swapping the comma's for semicolons to remove the errors that power BI gave. When there are no more error's there isn't any result in the calculated colum.

 

Can you help me further with this?

 

Below the code I have used:

 

 

LastStatus =
VAR temp =
ADDCOLUMNS (
SUMMARIZE ( 'Maint VW_DPR2_CheckLists'; [System]; "LastDate"; MAX( 'Maint VW_DPR2_CheckLists'[StartDate]) );
"Status"; LOOKUPVALUE (
'Maint VW_DPR2_CheckLists'[Status];
'Maint VW_DPR2_CheckLists'[System]; [System];
'Maint VW_DPR2_CheckLists'[StartDate]; [LastDate]
)
)
RETURN
MAXX ( FILTER ( temp; [System] = SELECTEDVALUE ( 'Maint VW_DPR2_CheckLists'[System] ) ); [Status] )

 

Kind regards and hope to hear from you soon,

 

 

Léjon

 

Thank yoy very much Xiaoxin Sheng. 

 

It works great!!!!!!!!!!!!!!!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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