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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
patlopes
Frequent Visitor

Cumulative Count of last avaialble stock value

Hi,

 

Having some trouble finding the right approach with a DAX measure, maybe someone can help.

 

I have the following scenario, Category and Product, and the available stock at given date to which corresponds one Version (Version is unique in each Product).

CategoryProductVersionPublished Date# Items
ShoesBoots723/09/202133
ShoesBoots828/10/202160
ShoesBoots928/10/202147
ShoesBoots1021/01/202250
ShoesTrainers723/09/202120
ShoesTrainers828/10/202132
ShoesTrainers928/10/202158
ShoesTrainers1024/01/202233
BottomsTrousers228/10/202134
BottomsTrousers304/01/202210
BottomsTrousers419/01/202215
BottomsTrousers519/01/202213
BottomsTrousers626/01/202235
BottomsTrousers702/02/202240
BottomsShorts228/10/202127
BottomsShorts317/12/20215
BottomsShorts419/01/202212
BottomsShorts527/01/202263
BottomsShorts627/01/202236
BottomsShorts727/01/202227
BottomsLeggings228/10/202123
BottomsLeggings304/01/202225
BottomsSkirts228/10/202130

 

For some products there are no values in some months - in this case I want to count the last available version.

 

Sometimes one product has more than one count per month - in this case I want to count only the last version in the month.

 

The final outcome should look as below.

The model has the table with the counts connected to a calendar table(continuous).

The x-axis in the graph is from Calendar table.

patlopes_1-1644839625109.png

 

 

 

Any help is appreciated,

Thank you

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Simple enough

Stock = 
VAR __yyyymm = MAX( DATES[YYYYMM] )
RETURN
    CALCULATE(
        SUMX(
            VALUES( INVT[Category] ),
            CALCULATE(
                SUMX(
                    VALUES( INVT[Product] ),
                    CALCULATE(
                        MAXX(
                            TOPN( 1, INVT, INVT[Published Date], DESC, INVT[Version], DESC ),
                            INVT[# Items]
                        )
                    )
                )
            )
        ),
        DATES[YYYYMM] <= __yyyymm
    ) + 0

CNENFRNL_0-1644863841232.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

Simple enough

Stock = 
VAR __yyyymm = MAX( DATES[YYYYMM] )
RETURN
    CALCULATE(
        SUMX(
            VALUES( INVT[Category] ),
            CALCULATE(
                SUMX(
                    VALUES( INVT[Product] ),
                    CALCULATE(
                        MAXX(
                            TOPN( 1, INVT, INVT[Published Date], DESC, INVT[Version], DESC ),
                            INVT[# Items]
                        )
                    )
                )
            )
        ),
        DATES[YYYYMM] <= __yyyymm
    ) + 0

CNENFRNL_0-1644863841232.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

ValtteriN
Super User
Super User

Hi,

You can use this kind of pattern to find the latest amount: 

Var cdate = max(table[Date])
var latest_ver = calculate(max(table[version]),all(table[Date]),table[Date]<=cdate)
return

CALCULATE(SUM(Table[items]),ALL(Table[Date]),Table[version]=latest_ver)
Ping me with @ if your have questions/problems

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN 

 

thank you for your quick reply. It's almost there, just one parameter missing. 

With your formula (thank you for it) i get below result.  

patlopes_1-1644852460349.png

In last month, 022022,  I only see one product, although I have stock for other products.

In 022022 I would like to see sum of all last versions per product independent of when they where published. 

 

 Thank you

 

Hi,

You can use the above logic + sumx to get the values for all the products.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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