Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cherrypbi
Advocate I
Advocate I

Last month total for a category (PREVIOUSMONTH does not work)

Hello,

I'm trying to get last month's total (which is December 2022) for Category = Apple with "PREVIOUSMONTH" function but it does not work. 

 

cherrypbi_0-1674071387803.png

 

 

 

Current formula that doesnt work: 

CALCULATE ( SUM ('RevenueTable'[Revenue] ) , FILTER ( 'RevenueTable' , PREVIOUSMONTH('RevenueTable'[Billing Month])) , FILTER ( 'RevenueTable' , 'RevenueTable'[product] = "Apple" ) )
 
 
This returns 129, instead of 107 (value I want), 
My formula adds everything in the table except 7/1/2022 which got omitted for some reason...any help is appreciated

 

cherrypbi_2-1674068600965.png

 

 

 

1 ACCEPTED SOLUTION
v-binbinyu-msft
Community Support
Community Support

Hi @cherrypbi ,

Please try below steps:

1. create a measure with below dax formula

Measure =
VAR cur_date =
    TODAY ()
VAR _total =
    CALCULATE (
        SUM ( 'Table'[Revenue] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Category] = "Apple"
                && DATEDIFF ( 'Table'[BillingMonth], TODAY (), MONTH ) = 1
        )
    )
RETURN
    _total

2.  add a card visual with measure 

vbinbinyumsft_0-1674096017675.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with calculated column formulas for year, Month name and Month number.  Sort the Month name by the Month number.  Create a relationship (Many to One and Single) from the Billing Month column to the Date column of the Calendar Table.  To your visual, drag year and month from the Calendar Table and Category from the RevenueTable.  Write these measures

Rev = SUM ('RevenueTable'[Revenue] )

Rev in previous month = calculate([Rev],previousmonth(Calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-binbinyu-msft
Community Support
Community Support

Hi @cherrypbi ,

Please try below steps:

1. create a measure with below dax formula

Measure =
VAR cur_date =
    TODAY ()
VAR _total =
    CALCULATE (
        SUM ( 'Table'[Revenue] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Category] = "Apple"
                && DATEDIFF ( 'Table'[BillingMonth], TODAY (), MONTH ) = 1
        )
    )
RETURN
    _total

2.  add a card visual with measure 

vbinbinyumsft_0-1674096017675.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

SivaMani
Resident Rockstar
Resident Rockstar

@cherrypbi, try this

Revenue PM = CALCULATE(
    SUM('RevenueTable'[Revenue]),
    'RevenueTable'[Category] = "Apple",
    PREVIOUSMONTH(LASTDATE('RevenueTable'[BillingMonth])),
    All('RevenueTable'[BillingMonth])
    )

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.