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
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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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

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.

Top Solution Authors