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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Custom Previous month

Hi Team,

I'm facing some challenges for creating the Custom PreviousMonth DAX function based on below mentioned calendar for 2024, Dateadd & PreviousMonth functions are not getting accurate here. I will be appriciated your suggestions!!

 

Customised Sales Calendar - 2024
Start DateClose Date
1/3/20241/31/2024
2/1/20242/29/2024
3/1/20244/1/2024
4/2/20244/30/2024
5/1/20245/31/2024
6/1/20247/1/2024
7/2/20247/31/2024
8/1/20249/3/2024
9/4/20249/30/2024
10/1/202410/31/2024
11/1/202412/2/2024
12/3/20241/2/2025

@PowerBI @PowerK @Jpower @GPower 

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Previous start date = 
VAR _selsdate =
    SELECTEDVALUE ( 'Table'[Start Date] )
RETURN
    CALCULATE (
        MAX ( 'Table'[Start Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Start Date] < _selsdate )
    )
Previous close date = 
VAR _selcdate =
    SELECTEDVALUE ( 'Table'[Close Date] )
RETURN
    CALCULATE (
        MAX ( 'Table'[Close Date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Close Date] < _selcdate )
    )

vyiruanmsft_0-1705027080552.png

Best Regards

Anonymous
Not applicable

Thanks for your reply... it is not supported for my requirement. The blow given DAX code gives me the selected month SalesCount. But i have to find the previous month SalesCount based on attached calendar month dates. It will be great help on this for to find the previousmonth count.

 

AS_Sold_CNT =
 
var SelectedMonthDateEndM = SELECTEDVALUE('Calendar'[CPO_SALES_RPT_END_DATE__c], MAX('Calendar'[CPO_SALES_RPT_END_DATE__c]))
var SelectedMonthDateStartM = SELECTEDVALUE('Calendar'[CPO_SALES_RPT_START_DATE__c], MIN('Calendar'[CPO_SALES_RPT_START_DATE__c]))
var IstSold = CALCULATE(COUNT('CPO Vehicle'[CPO_Vin__c]),
                            'CPO Vehicle'[Decert_Date_Fixed] = BLANK() || 'CPO Vehicle'[Decert_Date_Fixed]  > SelectedMonthDateEndM,
                            'CPO Vehicle Temp'[CPO_Reported_Sale_Date__c] >= SelectedMonthDateStartM,
                             'CPO Vehicle Temp'[CPO_Reported_Sale_Date__c] <= SelectedMonthDateEndM)
                       
 return
IF(IstSold = BLANK(), 0, IstSold)
Anonymous
Not applicable

Hi @Anonymous ,

Could you please provide some sample data in the tables 'CPO Vehicle' and  'CPO Vehicle Temp' (exclude sensitive data) with Text format and the expected result base on the provided sample data? It is better if can explain the calculation logic? It would be very helpful to find the solution. Thank you. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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