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
WdeVries
Regular Visitor

Calculate for the only the last month within a selected period

Hi,

 

I have trouble to create a measure that only calculates a value for the last month within a selected time period (not necessarily the current month..), the rest of the months in the selected period should be zero. The last filter is not working, Anyone ideas? Many thanks in advance!

 

PartOfMonth =
VAR DayOfMonth = DATEDIFF(
                                    EOMONTH(max(Dates[Dates]), -1),
                                    MAX(Dates[Dates]),
                                 day)
VAR DaysInMonth = datediff(
                                    eomonth(MAX(Dates[Dates]),-1),
                                    EOMONTH(MAX(Dates[Dates]), 0), DAY)
VAR PART = Divide(
                       DayOfMonth,
                       DaysInMonth,
                       Blank())
RETURN
CALCULATE(PART,
    FILTER(ALL(Dates[Dates]), MAX(Dates[month])))
4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Share some data, describe the question and show the expected result.  Your chances of getting a good solution become a lot more brighter when you describe your question rather than just post a formula.


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

Hi  @WdeVries  ,

According to your description, I create this data:

v-yangliu-msft_0-1615250408338.png

Here are the steps you can follow:

1. If the function behind Return has no specific meaning, you can directly return PART

Measure =
var _DayOfMonth=DATEDIFF(
                        EOMONTH(MAX('Table'[date]),-1),
                        MAX('Table'[date]),DAY)
VAR _DaysInMonth = datediff(
                                    EOMONTH(MAX('Table'[date]),-1),
                                    EOMONTH(MAX('Table'[date]), 0), DAY)
VAR _PART = Divide(
                       _DayOfMonth,
                       _DaysInMonth,
                       BLANK()
                      )


return                
_PART

2. Result:

v-yangliu-msft_1-1615250408343.jpeg

 

You can downloaded PBIX file from here

If the result is still incorrect, can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

VijayP
Super User
Super User

@WdeVries 

Try using ALLSELECTED instead of ALL In the Last Line and let me know!




Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
MY Blog || My YouTube Channel || Connect with me on Linkedin || My Latest Data Story - Ageing Analysis

Proud to be a Super User!


Hi VijayP,

Thank you for the quick reply, ALLSELECTED gives the same result. 

WdeVries_0-1614953828071.png

 

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.