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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Get the last date of the last month of a dataset

Hi,  

 

I try to calculate the last date from my dataset for the last month, the formula works : 

Measure = CALCULATE(LASTDATE(Inventory[History_Date]),MONTH(Inventory[History_Date])=MONTH(MAX(Inventory[History_Date]) - 1))
 
(on the 10/24/2022, returns the 09/28/2022 (last date of the last month in my dataset) )
 
 
However, when i use the measure in an other  CALCULATE formula, the result is wrong : the measure is interpreted as the last date of the current month instead if the last month
Test formula :
Nb_devices_M-1 = CALCULATE(DISTINCTCOUNT(Inventory[ID]),FILTER(Inventory,Inventory[History_Date]=[Measure]))
 
(on the 10/24/2022, returns the number of ID on the 10/24/2022, instead of the 09/28/2022 (last date of the last month in my dataset) )
 
Any idea ? 🤔
 
Thanks !
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Please update the formula of measure [Nb_devices_M-1] as below and check if it can return the correct result:

Nb_devices_M-1 =
VAR _lastdate = [Measure]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Inventory[ID] ),
        FILTER ( Inventory, Inventory[History_Date] = _lastdate )
    )

 

If the above one can't help you get the desired result, please provide some sample data in your table 'Inventory' (exclude sensitive data) with Text format and your expected result with backend logic and special examples. 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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @Anonymous ,

Whether your problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.

Best Regards

Anonymous
Not applicable

Hi @Anonymous ,

Please update the formula of measure [Nb_devices_M-1] as below and check if it can return the correct result:

Nb_devices_M-1 =
VAR _lastdate = [Measure]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Inventory[ID] ),
        FILTER ( Inventory, Inventory[History_Date] = _lastdate )
    )

 

If the above one can't help you get the desired result, please provide some sample data in your table 'Inventory' (exclude sensitive data) with Text format and your expected result with backend logic and special examples. 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

amitchandak
Super User
Super User

@Anonymous , openingbalancemonth of the month gives the value of last date of last month

 

You have to use the date table joined with History_Date

 

calculate(DISTINCTCOUNT(Inventory[ID]), openingbalancemonth (Date[Date]))

 

 

or

 

calculate(lastnonblankvalues(Inventory[History_Date], DISTINCTCOUNT(Inventory[ID])), previousmonth(Date[Date]))

 

Power BI Allocating Targets: openingbalancemonth, openingbalancequarter, openingbalanceyear: https://youtu.be/6lzYOXI5wfo

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.