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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Last value known per category association

Hello,


First of all I would like to thanks you for your help and apologize for my english, this is not my native language.

I am working on a Power BI desktop and I am struggling on a measure I am trying to create, but let me first introduce you to (what look like) my model : 

CptNico_1-1700498837202.png

 

So my data are like :

CUSTOMER table:

CptNico_0-1700500246983.png

 

ITEM table:

CptNico_1-1700500265848.png

 

MOVEMENT table:

CptNico_2-1700500291763.png

 

Let me skip the Calendar table, which I think is pretty clear for everyone 😉
Now what I am trying to do : a measure that give the lastest known state of my stock. 
So :

- If we have a data for the selected date, we pick the value

- If we don't have a value, we look for the lastest one.

 

Exptected : 
If I pick the 6th of November :

CptNico_3-1700500312242.png


If I pick the 4th of November :

CptNico_4-1700500328258.png

 

I can provide de different measure I tried, but since they are mainly tuned by ChatGPT... I don't think it will help a lot....
Thank you again for your help !

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi, I am not 100% sure about how the fact table looks like, but if there are some missing dates in the fact table, below is one of many ways to achieve it.

 

Jihwan_Kim_0-1700542721797.png

 

Jihwan_Kim_1-1700542738571.png

 

Lastest date with stocks: = 
VAR _lastnonblankdate =
    MAXX (
        FILTER (
            SUMMARIZE ( Movement, 'Calendar'[Date], Movement[stock_qty] ),
            'Calendar'[Date] < MAX ( 'slicer calendar'[Date] )
                && Movement[stock_qty] <> 0
        ),
        'Calendar'[Date]
    )
RETURN
    _lastnonblankdate

 

Lastest known stocks: = 
VAR _lastnonblankdate =
    MAXX (
        FILTER (
            SUMMARIZE ( Movement, 'Calendar'[Date], Movement[stock_qty] ),
            'Calendar'[Date] < MAX ( 'slicer calendar'[Date] )
                && Movement[stock_qty] <> 0
        ),
        'Calendar'[Date]
    )
RETURN
    CALCULATE ( SUM ( Movement[stock_qty] ), 'Calendar'[Date] = _lastnonblankdate )

 

    Microsoft MVP




If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.





LinkedIn
Visit my LinkedIn page





Outlook Booking
Schedule a short Teams meeting to discuss your question.




Helpful resources

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

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.