Forum Discussion
creating a measure that adds in implicit missing data
- Anonymous5 years ago
Hi CL7777 ,
You can create a measure as below:
Measure = VAR _curdate = MAX ( 'temp table'[Last Day of Month] ) VAR _curpart = MAX ( 'temp table'[Part Number] ) VAR _predate = CALCULATE ( MAX ( 'temp table'[Last Day of Month] ), FILTER ( ALL ( 'temp table' ), 'temp table'[Part Number] = _curpart && 'temp table'[Last Day of Month] < _curdate && NOT ( ISBLANK ( 'temp table'[QOH] ) ) && NOT ( ISBLANK ( 'temp table'[Cost] ) ) ) ) VAR _prevalue = CALCULATE ( MAX ( 'temp table'[QOH] ) * MAX ( 'temp table'[Cost] ), FILTER ( ALL ( 'temp table' ), 'temp table'[Part Number] = _curpart && 'temp table'[Last Day of Month] = _predate ) ) RETURN IF ( ISBLANK ( MAX ( 'temp table'[Cost] ) ) && ISBLANK ( MAX ( 'temp table'[QOH] ) ), _prevalue, MAX ( 'temp table'[QOH] ) * MAX ( 'temp table'[Cost] ) )Best Regards
Rena
I appreciate all of your help, I cannot use power query to make the table because my data set is created in Dax in BI using a summarize statement and is millions of lines. but I am almost there, one last thing I need help with to get this figured out. I created a table in Dax that has all the dates and data in there. it looks like this now (see sample table below)
I tried using your lastnonblank value measure statement to create the total value (QOH * Cost) for the last non-blank row in the table below (table called "temp table"). Im not getting values where the QOH and Cost is blank, in other words, its not retrieving the last non blank value of these and multiplying them together. Here is what Im using for the measure, what am I doing wrong?
| Last Day of Month | Part Number | Plant | QOH | Cost |
| 10/31/2020 | A | MfgSys | ||
| 9/30/2020 | A | MfgSys | ||
| 8/31/2020 | A | MfgSys | ||
| 7/31/2020 | A | MfgSys | ||
| 6/30/2020 | A | MfgSys | ||
| 5/31/2020 | A | MfgSys | ||
| 4/30/2020 | A | MfgSys | ||
| 3/31/2020 | A | MfgSys | ||
| 2/29/2020 | A | MfgSys | ||
| 1/31/2020 | A | MfgSys | ||
| 12/31/2019 | A | MfgSys | 71 | 4.37 |
| 11/30/2019 | A | MfgSys | ||
| 10/31/2019 | A | MfgSys | 74 | 4.43 |
| 9/30/2019 | A | MfgSys | ||
| 8/31/2019 | A | MfgSys | ||
| 7/31/2019 | A | MfgSys | 76 | 4.43 |
| 6/30/2019 | A | MfgSys | 82 | 4.43 |
| 5/31/2019 | A | MfgSys | 86 | 4.43 |
| 4/30/2019 | A | MfgSys | ||
| 3/31/2019 | A | MfgSys | ||
| 2/28/2019 | A | MfgSys | 98 | 4.43 |
| 1/31/2019 | A | MfgSys | ||
| 10/31/2020 | B | MfgSys | ||
| 9/30/2020 | B | MfgSys | ||
| 8/31/2020 | B | MfgSys | 18 | 222.12 |
| 7/31/2020 | B | MfgSys | 19 | 222.12 |
| 6/30/2020 | B | MfgSys | ||
| 5/31/2020 | B | MfgSys | 20 | 222.12 |
| 4/30/2020 | B | MfgSys | ||
| 3/31/2020 | B | MfgSys | 14 | 222.12 |
| 2/29/2020 | B | MfgSys | ||
| 1/31/2020 | B | MfgSys | 4 | 222.12 |
| 12/31/2019 | B | MfgSys | ||
| 11/30/2019 | B | MfgSys | 7 | 242.40 |
| 10/31/2019 | B | MfgSys | 8 | 242.40 |
| 9/30/2019 | B | MfgSys | ||
| 8/31/2019 | B | MfgSys | ||
| 7/31/2019 | B | MfgSys | 5 | 242.40 |
| 6/30/2019 | B | MfgSys | 7 | 242.40 |
| 5/31/2019 | B | MfgSys | 15 | 242.40 |
| 4/30/2019 | B | MfgSys | 8 | 242.40 |
| 3/31/2019 | B | MfgSys | ||
| 2/28/2019 | B | MfgSys | 12 | 242.40 |
| 1/31/2019 | B | MfgSys | 13 | 242.40 |
Hi CL7777 ,
You can create a measure as below:
Measure =
VAR _curdate =
MAX ( 'temp table'[Last Day of Month] )
VAR _curpart =
MAX ( 'temp table'[Part Number] )
VAR _predate =
CALCULATE (
MAX ( 'temp table'[Last Day of Month] ),
FILTER (
ALL ( 'temp table' ),
'temp table'[Part Number] = _curpart
&& 'temp table'[Last Day of Month] < _curdate
&& NOT ( ISBLANK ( 'temp table'[QOH] ) )
&& NOT ( ISBLANK ( 'temp table'[Cost] ) )
)
)
VAR _prevalue =
CALCULATE (
MAX ( 'temp table'[QOH] ) * MAX ( 'temp table'[Cost] ),
FILTER (
ALL ( 'temp table' ),
'temp table'[Part Number] = _curpart
&& 'temp table'[Last Day of Month] = _predate
)
)
RETURN
IF (
ISBLANK ( MAX ( 'temp table'[Cost] ) ) && ISBLANK ( MAX ( 'temp table'[QOH] ) ),
_prevalue,
MAX ( 'temp table'[QOH] ) * MAX ( 'temp table'[Cost] )
)Best Regards
Rena
- CL77775 years agoHelper III
Thank you so much, that is exactly what I was looking for ! much appreciated