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
Sorry I can't share either of it.
Can you paste the formula then
- Anonymous5 years agoNot applicable
Actually it is on the virtual machine, so I can't provide anything.
But I assure you, formula is exactly same as yours.- richbenmintz5 years ago
Resident Rockstar
Hi Anonymous ,
Are you not able to copy and paste the formula code from the VM? I believe that the code is the same, however Without seeing the formula, and the name of your attributes is it really hard to troubleshoot this for you.
The error seems to be pointing to the formula engine trying to compare the value of the switch condition to true(). so if the comparison does not return a true() or false() it will fail.
- Anonymous5 years agoNot applicable
Hi richbenmintz I don't know what happened but it worked man!! It is working just fine now.
I need a little favour from you, can you please help me how to determine the maximum and minimum value from the selection of Month_year 2.For example, If Current month & Mar-21 is selected from the slicer, how do I determine Current Month is bigger value and Mar-21 is lesser.
Let me know if you need separate question for it on community. Accordingly I'll accept your solution and close this thread.