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
Krishna090
New Member

How to get previous months all days and current month today

Hi Team, can someone tell me how to get below one.

with  below code, I'm getting all the days.

Days in month = IF(DATEDIFF(DAY(TODAY())=DATE(YEAR(today()), MONTH(today()), 1),NOW(),Day),DATEDIFF([First date of month],R_AMHS_HLY_UPTIME_DET_VW[Last date of month],DAY)+1)

but I need to get current month current day and previous months all days
req.JPG
 Updating Media

 

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

Hi, @Krishna090 ;

You could try it.

Days in month =
IF (
    EOMONTH ( [First date of month], 0 ) <> EOMONTH ( TODAY (), 0 ),
    DATEDIFF (
        [First date of month],
        R_AMHS_HLY_UPTIME_DET_VW[Last date of month],
        DAY
    ) + 1,
    DATEDIFF ( [First date of month], TODAY (), DAY ) + 1
)

If not right, can you share your simple data and the result what you want to output?
Best Regards,
Community Support Team _ Yalan Wu
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

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @Krishna090 ;

You could try it.

Days in month =
IF (
    EOMONTH ( [First date of month], 0 ) <> EOMONTH ( TODAY (), 0 ),
    DATEDIFF (
        [First date of month],
        R_AMHS_HLY_UPTIME_DET_VW[Last date of month],
        DAY
    ) + 1,
    DATEDIFF ( [First date of month], TODAY (), DAY ) + 1
)

If not right, can you share your simple data and the result what you want to output?
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yalanwu-msft  thanks for the quick reply and similarly  I tried day before yesterday but mine is manual way. Where need to update the query based on the month no.
And below is the query I tried.

DAYS MONTH = IF (
'R_AMHS_HLY_UPTIME_DET_VW'[Month No] = 8,
DAY ( EOMONTH ( TODAY (), -3 ) ),
IF (
'R_AMHS_HLY_UPTIME_DET_VW'[Month No] = 9,
DAY ( EOMONTH ( TODAY (), -2 ) ),
IF (
'R_AMHS_HLY_UPTIME_DET_VW'[Month No] = 10,
DAY ( EOMONTH ( TODAY (), -1 ) ),
DAY ( TODAY () )
)
)
).

And ur method is working fine.
Ashish_Mathur
Super User
Super User

Hi,

Assuming there is a date column i your dataset, you should create a Calendar Table.  Create a relationship (Many to One and Single) from the Date column of your dataset to the Date column of the Calendar Table.  In the Calendar Table, write calculated column formulas to extract Year, Month name and Month number.  Sort the Month name by the Month number.  To your matrix visual, drag Year and Month name to the column section.  Write this measure

Days in month = countrows(Calendar)

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Assuming your visual shows months:

 

CALCULATE(COUNTROWS('Dates'),'Dates'[Date]<=TODAY())

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.