Forum Discussion
previous month value
Hi,
i am using below measure for previous month but when nothning is selected the card visual is showing (Blank). i want to show constant value for previous month and change accordeingly month selection in slicer.
please guide
Previous month Count =
VAR __currentDate = EOMONTH ( MAX ( Sheet1[date] ), -1 )
RETURN
CALCULATE (
COUNTROWS ( Sheet1 ),
DATESBETWEEN ( Sheet1[date],
EOMONTH ( __currentDate, -1 ) + 1, __currentDate )
)
- Anonymous5 years ago
Hi Anonymous
Due to I don't know your data model, I build a sample to have a test.
Sample is from 2020/11/01 to 2021/03/04
I build a YearMonth column in my sample table.
YearMonth = YEAR('Sheet1'[Date])*100+MONTH('Sheet1'[Date])Build a slicer table.
Slicer = VALUES('Sheet1'[YearMonth])Try IF and Isfiltered function in measure.
Measure:
Measure = VAR _SEl = SELECTEDVALUE(Slicer[YearMonth]) VAR _Previous = MAXX(FILTER(ALL(Slicer),Slicer[YearMonth]<_SEl),Slicer[YearMonth]) VAR _CURRENT = YEAR(TODAY())*100+MONTH(TODAY()) Return IF(ISFILTERED(Slicer[YearMonth]),CALCULATE(COUNTROWS(Sheet1),FILTER(ALL(Sheet1),Sheet1[YearMonth] = _Previous)),CALCULATE(COUNTROWS(Sheet1),FILTER(ALL(Sheet1),Sheet1[YearMonth] = _CURRENT-1)))Result:
By default it will show values in previous month of the current month.
If I select slicer, it will show values of previous month according to selection.
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.
3 Replies
- amitchandakSuper User
Anonymous , Please use time intelligence with date table
example
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA- AnonymousNot applicable
amitchandak thanks
but it whows when i select option in slicer not without thati wish have visual which show result even i have not selected any option in slicer
Please guide me
- AnonymousNot applicable
Hi Anonymous
Due to I don't know your data model, I build a sample to have a test.
Sample is from 2020/11/01 to 2021/03/04
I build a YearMonth column in my sample table.
YearMonth = YEAR('Sheet1'[Date])*100+MONTH('Sheet1'[Date])Build a slicer table.
Slicer = VALUES('Sheet1'[YearMonth])Try IF and Isfiltered function in measure.
Measure:
Measure = VAR _SEl = SELECTEDVALUE(Slicer[YearMonth]) VAR _Previous = MAXX(FILTER(ALL(Slicer),Slicer[YearMonth]<_SEl),Slicer[YearMonth]) VAR _CURRENT = YEAR(TODAY())*100+MONTH(TODAY()) Return IF(ISFILTERED(Slicer[YearMonth]),CALCULATE(COUNTROWS(Sheet1),FILTER(ALL(Sheet1),Sheet1[YearMonth] = _Previous)),CALCULATE(COUNTROWS(Sheet1),FILTER(ALL(Sheet1),Sheet1[YearMonth] = _CURRENT-1)))Result:
By default it will show values in previous month of the current month.
If I select slicer, it will show values of previous month according to selection.
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.