Forum Discussion
Power BI : Default Current Month & Previous Month Selection
- 5 years ago
Hi Anonymous ,
The Following would have you add three new columns:
1. A deterministic Month Year Column to ensure you get the correct max month
- this I added into the source data I mocked up, the format should be yyyyMM
2. A Year Month Number that creates a sequence of months that allow us to get the max and subtract 1 for the previous month
YearMonthNumber = Left([MonthYear],4) * 12 -1 + RIGHT([MonthYear],2)3. The Column you requested
Month Year 2 = var _maxMonth = CALCULATE(max('test'[YearMonthNumber]), ALL('test')) var _month = [MonthYear] return SWITCH( true(), [YearMonthNumber] = _maxMonth, "Current Month", [YearMonthNumber] = _maxMonth-1, "Previous Month", [Year-Month] )See the screen shot below. displaying the results
Hi Anonymous ,
The Following would have you add three new columns:
1. A deterministic Month Year Column to ensure you get the correct max month
- this I added into the source data I mocked up, the format should be yyyyMM
2. A Year Month Number that creates a sequence of months that allow us to get the max and subtract 1 for the previous month
YearMonthNumber = Left([MonthYear],4) * 12 -1 + RIGHT([MonthYear],2)
3. The Column you requested
Month Year 2 =
var _maxMonth = CALCULATE(max('test'[YearMonthNumber]), ALL('test'))
var _month = [MonthYear]
return
SWITCH(
true(),
[YearMonthNumber] = _maxMonth, "Current Month",
[YearMonthNumber] = _maxMonth-1, "Previous Month",
[Year-Month]
)
See the screen shot below. displaying the results
- Anonymous5 years agoNot applicable
Hi richbenmintz thank you for your reply.
I am getting below error when tried your switch formula
"SWITCH does not support comparing values of type True/False with values of type Number. Try using VALUE or FORMAT function to convert one of the values"
I am not sure why this error as none of my data type is True/False.
- richbenmintz5 years ago
Resident Rockstar
Hi Anonymous ,
Are you able to provide either sample data or a sample pbix file?
- Anonymous5 years agoNot applicable
Sorry I can't share either of it.