Forum Discussion
LASTNONBLANKVALUE challenging problem
Hi, Arnault_
Please correct me if I wrongly understood your question.
I tried the below measure, and I think it works.
Jihwan Kim
If this post helps, then please consider accept it as the solution to help the other members find it more quickly.
- Arnault_5 years agoResolver III
Hi Jihwan_Kim ,
Thank you for your time and proposal.
Your measure meets one of the requirements since the inventory values are displayed for every day even when there is no transaction. Still, there is something which does not work.
In my dataset, we can select the 5th of November to illustrate the problem. On that particular date, there are several transactions and at least one transaction per warehouse. You measure does not take into account the fact there are 2 warehouses and it only selects the latest transaction of this day. Normally, the latest transaction for BDX and the latest transaction for DUB should be selected and aggregated. This works in my measure. That's why in my measure I use a virtual table with product_id, version_id and warehouse. Maybe I should create a unique id combining these columns. What do you think?
- Jihwan_Kim5 years agoSuper User
Hi, Arnault_
Thank you very much for your feedback, and I could understand much better.
If it is OK with you, please try the below.
lastupdateinventory fix =VAR maxdate =MAX ( 'Date'[Date] )VAR lastnonblankinventorybalance =CALCULATE (LASTNONBLANKVALUE ('Date'[Date],SUMX (SUMMARIZE (MyData,MyData[warehouse],MyData[product_id],MyData[version_id],"@maxseqbalance",CALCULATE (SUM ( MyData[ending_balance] ),FILTER ( MyData, MyData[sequence_no] = MAX ( MyData[sequence_no] ) ))),[@maxseqbalance])),FILTER ( ALLSELECTED ( 'Date' ), 'Date'[Date] <= maxdate ))RETURNlastnonblankinventorybalanceHi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster.
- Arnault_5 years agoResolver III
Hi Jihwan_Kim ,
Thank you again for your time and efforts.
We are getting close to the requirements. I am just thinking that maybe DAX is not the best approach to obtain what I am looking for. Maybe some pre-build in SQL would be better. Anyway, here is the remaining issue: the total on the right is not working properly. The first table corresponds to my measure, the 2nd to yours.
You can see two examples highlithed. On the 12th of May, the total shows 320 650 which corresponds to the 1st item only. In your measure the last non blank value is populated for the 2nd item but it is not taken into account in the sum (in the total on the right).
For the next row, on the 13th of May, it works because there are transactions on that day and as you can see it with my measure (first table), the sumx works perfectly.
From a business perspective, if I want to know the quantity in stock for these 2 items (in total) at the end of the 12th of May, your measure would tell me 320 650, instead of (320 650 + 432 400). Voilà.