Forum Discussion
Missing values per week - return latest active value
- Anonymous5 years ago
Hi Anonymous
If you have a large number of weeks, you may need to use dax to build a separate week table.
And amitchandak 's measure works well if you build relationships between two tables.
You can try my measure if you don't want to build relationships between two tables.
Firstly, we add a WeekNum column in Price Table.
WeekNum = SUBSTITUTE('Price'[Week],"Week ","")Change the column type from text to whole number.
Then build Allweek Table.
AllWeek = ADDCOLUMNS(GENERATESERIES(MIN('Price'[WeekNum]),MAX('Price'[WeekNum]),1),"Week","Week"&" "&[Value])Measurez:
Price = VAR _P1 = CALCULATE ( MAX ( 'Price'[Price] ), FILTER ( 'Price', 'Price'[Week] = MAX ( AllWeek[Week] ) ) ) VAR _MaxNum = MAXX ( FILTER ( ALL ( 'Price' ), 'Price'[WeekNum] <= MAX ( AllWeek[Value] ) ), 'Price'[WeekNum] ) VAR _P2 = CALCULATE ( MAX ( 'Price'[Price] ), FILTER ( 'Price', 'Price'[WeekNum] = _MaxNum ) ) RETURN IF ( _P1 = BLANK (), _P2, _P1 )Result:
You can download the pbix file from this link: Missing values per week - return latest active value
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous
If you have a large number of weeks, you may need to use dax to build a separate week table.
And amitchandak 's measure works well if you build relationships between two tables.
You can try my measure if you don't want to build relationships between two tables.
Firstly, we add a WeekNum column in Price Table.
WeekNum = SUBSTITUTE('Price'[Week],"Week ","")
Change the column type from text to whole number.
Then build Allweek Table.
AllWeek = ADDCOLUMNS(GENERATESERIES(MIN('Price'[WeekNum]),MAX('Price'[WeekNum]),1),"Week","Week"&" "&[Value])
Measurez:
Price =
VAR _P1 =
CALCULATE (
MAX ( 'Price'[Price] ),
FILTER ( 'Price', 'Price'[Week] = MAX ( AllWeek[Week] ) )
)
VAR _MaxNum =
MAXX (
FILTER ( ALL ( 'Price' ), 'Price'[WeekNum] <= MAX ( AllWeek[Value] ) ),
'Price'[WeekNum]
)
VAR _P2 =
CALCULATE (
MAX ( 'Price'[Price] ),
FILTER ( 'Price', 'Price'[WeekNum] = _MaxNum )
)
RETURN
IF ( _P1 = BLANK (), _P2, _P1 )
Result:
You can download the pbix file from this link: Missing values per week - return latest active value
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous,
thanks for the help. I have been able to rebuild your example.
Now There is an additional level of complexity in this.
The data is also on item and customer level.
How do I work this into your example?
Example data:
Week - item - customer - price
Week 1 - item a - cust 1 - 1,83
Week 1 - item a - cust 2 - 1,85
Week 2 - item b - cust 1 - 2,50
Week 2 - item a - cust 2 - 1,86
Week 3 - item a - cust 1 - 1,85
Week 5 - item b - cust 1 - 2,60
Week 6 - item a - cust 1 - 1,86
etc.
From this I want to be able to look at the price per customer and calculate (using the cost price per customer) the margin of each item per week.
I created a file with an example in.