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
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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft,

 

 

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