Forum Discussion
Using variable to calculate data of previous date & current date
Greetings all,
and Have a nice Monday 😚
1. I am in need of calculate data of current date, but need to pick up result form the previous date.
(Because my data is too much with variety of date, Line, File No, Description, and they are also 04 slicers which have to be selected for filter & I have just pick up 1 line to make an example for forcusing 🙂)
2. From the initial data table, I would like to calculate 3 kind of column are PREVIOUS, TODAY & ACCUMULATATION.
3. I have done to calculate TODAY Operation WIP as below measure that I have learnt from Anonymous ^^, but meet challanges to calculate the two others.
My initial data table is:
| Date | Line | File No | Description | Op. No | Q'ty |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 1 | 760 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 2 | 1398 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 3 | 1664 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 4 | 1715 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 5 | 1783 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 6 | 1758 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 7 | 1508 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 8 | 1434 |
| 6/1/2021 | LINE 5 | VSCG213604 | 94 | 9 | 1444 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 1 | 2155 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 2 | 2304 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 3 | 1811 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 4 | 1773 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 5 | 1950 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 6 | 1867 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 7 | 1961 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 8 | 1737 |
| 6/2/2021 | LINE 5 | VSCG213604 | 94 | 9 | 2070 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 1 | 2279 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 2 | 2131 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 3 | 1926 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 4 | 1891 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 5 | 2052 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 6 | 2112 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 7 | 2046 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 8 | 2097 |
| 6/3/2021 | LINE 5 | VSCG213604 | 94 | 9 | 2026 |
Today WIP =
VAR CurOp = Data[Op. No]
VAR T1=FILTER(Data,Data[Description]=EARLIER(Data[Description])&&Data[Date]=EARLIER(Data[Date])&&Data[Line]=EARLIER(Data[Line])&&Data[File No]=EARLIER(Data[File No]))
VAR CurAcc = SUMX(FILTER(T1,Data[Op. No]=CurOp),[Q'ty])
VAR PreviousAcc = SUMX(FILTER(T1,Data[Op. No]=CurOp-1),[Q'ty])
RETURN
if(CurOp=1,0,
(CurAcc-PreviousAcc)/COUNTAX(FILTER(T1,Data[Op. No]=CurOp),[Q'ty]))
- Anonymous4 years ago
My bad...mistakenly clicked the button to accept the solution...
I modified the one from Anonymous a little bit
Previous WIP1 = CALCULATE(SUM([Today WIP]),FILTER('Data', 'Data'[Description]=EARLIER('Data'[Description]) &&'Data'[Date]<EARLIER('Data'[Date]) &&'Data'[Line]=EARLIER('Data'[Line]) &&'Data'[File No]=EARLIER('Data'[File No]) &&[Op. No]=EARLIER('Data'[Op. No])))Anonymous how can I undo Accept the solution?
8 Replies
- AnonymousNot applicable
thongnguyen2414
I created today WIP and previousdate WIP columns with a bit simplified logic, please check the dax for detail.Today WIP =
var curOPno = [Q'ty]
var PreOpno = CALCULATE(SUM([Q'ty]),FILTER('Data',
'Data'[Description]=EARLIER('Data'[Description])
&&'Data'[Date]=EARLIER('Data'[Date])
&&'Data'[Line]=EARLIER('Data'[Line])
&&'Data'[File No]=EARLIER('Data'[File No])
&&[Op. No]=EARLIER('Data'[Op. No])-1))
Return IF([Op. No]=1,0,curOPno-PreOpno)Previous WIP =
CALCULATE(MAX([Today WIP]),FILTER('Data',
'Data'[Description]=EARLIER('Data'[Description])
&&'Data'[Date]=EARLIER('Data'[Date])-1
&&'Data'[Line]=EARLIER('Data'[Line])
&&'Data'[File No]=EARLIER('Data'[File No])
&&[Op. No]=EARLIER('Data'[Op. No])))'Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.- thongnguyen2414Frequent Visitor
Dear Anonymous
Thank you so much for your advice.
- thongnguyen2414Frequent Visitor
I tried to calcualte the Previous date WIP by the below:
Previous WIP = VAR CurOp = Data[Op. No] VAR T1=FILTER(Data,Data[Description]=EARLIER(Data[Description])&&Data[Date]=EARLIER(Data[Date])-1 &&Data[Line]=EARLIER(Data[Line])&&Data[File No]=EARLIER(Data[File No])) VAR CurAcc = SUMX(FILTER(T1,Data[Op. No]=CurOp),[Q'ty]) VAR PreviousAcc = SUMX(FILTER(T1,Data[Op. No]=CurOp-1),[Q'ty]) RETURN if(CurOp=1,0, (CurAcc-PreviousAcc)/COUNTAX(FILTER(T1,Data[Op. No]=CurOp),[Q'ty]))On the June - 02 , the chart is showing correct, but not for Op. No 4 & 5
And on the June-3, calculation became wrong properly 😞
- thongnguyen2414Frequent Visitor
Hi
Can you please kindly advise if there is something wrong with the Variable calculation for Previuos date?
- AnonymousNot applicable
My bad...mistakenly clicked the button to accept the solution...
I modified the one from Anonymous a little bit
Previous WIP1 = CALCULATE(SUM([Today WIP]),FILTER('Data', 'Data'[Description]=EARLIER('Data'[Description]) &&'Data'[Date]<EARLIER('Data'[Date]) &&'Data'[Line]=EARLIER('Data'[Line]) &&'Data'[File No]=EARLIER('Data'[File No]) &&[Op. No]=EARLIER('Data'[Op. No])))Anonymous how can I undo Accept the solution?
- thongnguyen2414Frequent Visitor
Hello
Could any one kindly help me to figure out how to calculate for the 'previous date Operation WIP' & 'ACCUM. Operation WIP' ? I tried but still not successfully.