Forum Discussion
Show Prior Week Values together with Current Week Values
- 2 years ago
Hi,
I am not sure how your datamodel looks like, but I think it depends on how your calendar table looks like and how the relationship between the fact table and the calendar table looks like.
I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a solution for your datamodel.
Unloaded container this week: = CALCULATE ( COUNTROWS ( DISTINCT ( Data[Container ID] ) ), USERELATIONSHIP ( 'Calendar'[Date], Data[Unloaded On] ) )Loaded container previous week: = VAR _currentyear = MAX ( 'Calendar'[Year] ) VAR _currentweek = MAX ( 'Calendar'[Week Number] ) VAR _yearcondition = IF ( _currentweek <> 1, _currentyear, _currentyear - 1 ) VAR _previousweek = IF ( _currentweek <> 1, _currentweek - 1, MAXX ( FILTER ( ALL ( 'Calendar' ), 'Calendar'[Year] = _currentyear - 1 ), 'Calendar'[Week Number] ) ) RETURN CALCULATE ( COUNTROWS ( DISTINCT ( Data[Container ID] ) ), FILTER ( ALL ( 'Calendar' ), 'Calendar'[Year] = _yearcondition && 'Calendar'[Week Number] = _previousweek ) )
Hi,
I am not sure how your datamodel looks like, but I think it depends on how your calendar table looks like and how the relationship between the fact table and the calendar table looks like.
I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file. I hope the below can provide some ideas on how to create a solution for your datamodel.
Unloaded container this week: =
CALCULATE (
COUNTROWS ( DISTINCT ( Data[Container ID] ) ),
USERELATIONSHIP ( 'Calendar'[Date], Data[Unloaded On] )
)
Loaded container previous week: =
VAR _currentyear =
MAX ( 'Calendar'[Year] )
VAR _currentweek =
MAX ( 'Calendar'[Week Number] )
VAR _yearcondition =
IF ( _currentweek <> 1, _currentyear, _currentyear - 1 )
VAR _previousweek =
IF (
_currentweek <> 1,
_currentweek - 1,
MAXX (
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Year] = _currentyear - 1 ),
'Calendar'[Week Number]
)
)
RETURN
CALCULATE (
COUNTROWS ( DISTINCT ( Data[Container ID] ) ),
FILTER (
ALL ( 'Calendar' ),
'Calendar'[Year] = _yearcondition
&& 'Calendar'[Week Number] = _previousweek
)
)