Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Power BI : Default Current Month & Previous Month Selection

Hi All, I am working on monthly sales report which fetches its data from monthly invoice excel files as and when data available. i.e June-2021 file will contain data of June sales data.   In this...
  • richbenmintz's avatar
    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