Forum Discussion
Last value for each customer
- Anonymous4 years ago
Hi Anonymous ,
Here's my solution.
1.Create a calendar table and there's no relationship between two tables.
Calendar = ADDCOLUMNS(CALENDARAUTO(),"Weeknum",WEEKNUM([Date],2))2.Create a Weeknum column in Arkusz1 table.
Weeknum = WEEKNUM([Date],2)3.Measure 3 is the measure you created.
Measure 2 = SUMX ( VALUES('Arkusz1'[Customer]), CALCULATE ( SUM('Arkusz1'[Measure]), LASTDATE ( 'Arkusz1'[Date] ) ) )4.Create the following measure
LastDateByWeeknumWithoutBlank = var _value=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum]))) var _valuelastweek=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])-1)) return IF(_value=BLANK(),_valuelastweek,_value)5.If you only want to limit the number of weeks to only the number of weeks in your main table.
Create a flag measure and put it into Filters.
flag = var _max=MAXX(ALL(Arkusz1),[Weeknum]) var _min=MINX(ALL(Arkusz1),[Weeknum]) return IF(_min<=MAX('Calendar'[Weeknum])&&_max>=MAX('Calendar'[Weeknum]),1)Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
Here's my solution.
1.Create a calendar table and there's no relationship between two tables.
Calendar = ADDCOLUMNS(CALENDARAUTO(),"Weeknum",WEEKNUM([Date],2))
2.Create a Weeknum column in Arkusz1 table.
Weeknum = WEEKNUM([Date],2)
3.Measure 3 is the measure you created.
Measure 2 = SUMX (
VALUES('Arkusz1'[Customer]),
CALCULATE ( SUM('Arkusz1'[Measure]), LASTDATE ( 'Arkusz1'[Date] ) )
)
4.Create the following measure
LastDateByWeeknumWithoutBlank =
var _value=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])))
var _valuelastweek=CALCULATE([Measure 2],FILTER('Arkusz1',[Weeknum]=MAX('Calendar'[Weeknum])-1))
return
IF(_value=BLANK(),_valuelastweek,_value)
5.If you only want to limit the number of weeks to only the number of weeks in your main table.
Create a flag measure and put it into Filters.
flag = var _max=MAXX(ALL(Arkusz1),[Weeknum])
var _min=MINX(ALL(Arkusz1),[Weeknum])
return IF(_min<=MAX('Calendar'[Weeknum])&&_max>=MAX('Calendar'[Weeknum]),1)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.