Forum Discussion
SirBI
3 years agoFrequent Visitor
Previous Month Value
I have the below DEX (New Column) to find the previous value based off text date and value. See example table below.
PreviousMonthlyValue =
MAXX (
FILTER (
'Monthly Request',
'Monthly Request'[RequestBucket] = EARLIER ( 'Monthly Request'[RequestBucket])
&& 'Monthly Request'[YearMonth]
= EARLIER ( 'Monthly Request'[YearMonth] ) - 1
),
'Monthly Request'[totalCount]
)
This works until I get to December and previous value of Jan is not found.
How can I resolve this issue?
Is this something do do with the ordering of Year Month going from 202201>202112?
| YearMonth (Whole Number) | PreviousMonthlyValue | Request Bucket (Text) | TotalCount (Whole Number) |
| 202202 | 25,000 | Red | 40,000 |
| 202202 | 8,000 | Green | 12,000 |
| 202201 | Red | 25,000 | |
| 202201 | Green | 8,000 | |
| 202212 | 50 | Red | 14,000 |
| 202212 | 10 | Green | 2,000 |
| 202211 | (Null) | Red | 50 |
| 202211 | (Null) | Green | 10 |
- Anonymous3 years ago
Hi SirBI ,
Please update the formula of the calculated column [PreviousMonthlyValue] as below and you can get the expected result...
PreviousMonthlyValue = VAR _premonth = CALCULATE ( MAX ( 'Monthly Request'[YearMonth] ), FILTER ( 'Monthly Request', 'Monthly Request'[RequestBucket] = EARLIER ( 'Monthly Request'[RequestBucket] ) && 'Monthly Request'[YearMonth] < EARLIER ( 'Monthly Request'[YearMonth] ) ) ) RETURN MAXX ( FILTER ( 'Monthly Request', 'Monthly Request'[RequestBucket] = EARLIER ( 'Monthly Request'[RequestBucket] ) && 'Monthly Request'[YearMonth] = _premonth ), 'Monthly Request'[totalCount] )Best Regards
2 Replies
- AnonymousNot applicable
Hi SirBI ,
Please update the formula of the calculated column [PreviousMonthlyValue] as below and you can get the expected result...
PreviousMonthlyValue = VAR _premonth = CALCULATE ( MAX ( 'Monthly Request'[YearMonth] ), FILTER ( 'Monthly Request', 'Monthly Request'[RequestBucket] = EARLIER ( 'Monthly Request'[RequestBucket] ) && 'Monthly Request'[YearMonth] < EARLIER ( 'Monthly Request'[YearMonth] ) ) ) RETURN MAXX ( FILTER ( 'Monthly Request', 'Monthly Request'[RequestBucket] = EARLIER ( 'Monthly Request'[RequestBucket] ) && 'Monthly Request'[YearMonth] = _premonth ), 'Monthly Request'[totalCount] )Best Regards
- Greg_DecklerCommunity Champion
SirBI Well, if you have an actual date column available you can use EOMONTH. If not, you could use RIGHT to check the last 2 digits and if they are 01 then subtract 89