Forum Discussion
Prior month calculations (specific date range)
- 7 years ago
Hi snandy2011,
I made one sample for your reference. You can refer to the steps as below to meet your requirement.
1. Enter the sample data and create a dimtime table.
dimtime = CALENDARAUTO()
Month = FORMAT(dimtime[Date],"mmm")
weekinmonth = CONCATENATE(dimtime[Month],"-week"&1 + WEEKNUM ( dimtime[Date] )-WEEKNUM( STARTOFMONTH (dimtime[Date])))
2. Create a measure as below.
Measure = VAR Year = YEAR ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR month = MONTH ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR day = DAY ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR may = YEAR ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR mam = MONTH ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR maxday = DAY ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) ) VAR todayweek = CONCATENATE ( FORMAT ( TODAY (), "mmm" ), "-week" & 1 + WEEKNUM ( TODAY () ) - WEEKNUM ( DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ) ) ) RETURN IF ( SELECTEDVALUE ( dimtime[weekinmonth] ) = BLANK () && SELECTEDVALUE ( dimtime[Month] ) = BLANK (), BLANK (), IF ( FORMAT ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ), "mmm" ) = FORMAT ( TODAY (), "mmm" ), CALCULATE ( SUM ( 'Poker Profit'[Gross Gaming Revenue] ), FILTER ( ALL ( dimtime ), dimtime[Date] >= DATE ( Year, month - 1, day ) && dimtime[Date] <= DATE ( may, mam - 1, maxday ) ) ), CALCULATE ( SUM ( 'Poker Profit'[Gross Gaming Revenue] ), DATEADD ( dimtime[Date], -1, MONTH ) ) ) )Then we can get the result as we excepted.
For more details, please check the pbix as attached.
Regards,
Frank
Hi snandy2011,
I made one sample for your reference. You can refer to the steps as below to meet your requirement.
1. Enter the sample data and create a dimtime table.
dimtime = CALENDARAUTO()
Month = FORMAT(dimtime[Date],"mmm")
weekinmonth = CONCATENATE(dimtime[Month],"-week"&1 + WEEKNUM ( dimtime[Date] )-WEEKNUM( STARTOFMONTH (dimtime[Date])))
2. Create a measure as below.
Measure =
VAR Year =
YEAR ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR month =
MONTH ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR day =
DAY ( MINX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR may =
YEAR ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR mam =
MONTH ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR maxday =
DAY ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ) )
VAR todayweek =
CONCATENATE (
FORMAT ( TODAY (), "mmm" ),
"-week"
& 1 + WEEKNUM ( TODAY () )
- WEEKNUM ( DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 1 ) )
)
RETURN
IF (
SELECTEDVALUE ( dimtime[weekinmonth] ) = BLANK ()
&& SELECTEDVALUE ( dimtime[Month] ) = BLANK (),
BLANK (),
IF (
FORMAT ( MAXX ( RELATEDTABLE ( 'Poker Profit' ), 'Poker Profit'[Date] ), "mmm" )
= FORMAT ( TODAY (), "mmm" ),
CALCULATE (
SUM ( 'Poker Profit'[Gross Gaming Revenue] ),
FILTER (
ALL ( dimtime ),
dimtime[Date]
>= DATE ( Year, month - 1, day )
&& dimtime[Date]
<= DATE ( may, mam - 1, maxday )
)
),
CALCULATE (
SUM ( 'Poker Profit'[Gross Gaming Revenue] ),
DATEADD ( dimtime[Date], -1, MONTH )
)
)
)
Then we can get the result as we excepted.
For more details, please check the pbix as attached.
Regards,
Frank
- snandy20117 years agoHelper IV
Hi v-frfei-msft,
Absolutely 100 % worked your formula.You just made my day. I just omitted your weekinmonth conecpt.Beacuse i already made a week column in previous.And it worked as i expected.
We generally knew simple previous month concept.but never did, with specific date range. It will give us more compact analysis and comparison between current and previous month in terms of growth,profit margin etc. You just made it so simple.So, double kudos for that.
Thanks once again for your solution and reply.
Sincerely,
snandy