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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Need help on writing DAX queries based date and time

On the 8th business day of a month onwards I would like to show the data till last month (Dec)and before the 8th business day I would like to show the data for the month before the last month(Nov). 

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

Hi, @Anonymous ;

You could add another measure as rank Business day measure. then modify your meaure.

1. rank measure.

rank = RANKX(FILTER(ALL(Table1),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0)&&WEEKDAY([Date],2)<6),CALCULATE(MIN([Date])),,ASC)

2.modify your measure.

YTD = 
VAR EightBusinessday =
     MINX(FILTER(ALL(Table1),EOMONTH([Date],0)=EOMONTH(MAX('Table1'[Date]),0)&&[rank]=8),[Date])
VAR EndDate =
    IF (
        TODAY () < EightBusinessday,
        EOMONTH ( TODAY (), -2 ),
        EOMONTH ( TODAY (), -1 )
    )
RETURN
    CALCULATE (
        FactLaborBudgetHourBV[M_BudgetLaborHour],
        KEEPFILTERS ( DimDate[Date] <= EndDate )
    )

 The final output is shown below:

vyalanwumsft_0-1643093191386.png


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

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

You could add another measure as rank Business day measure. then modify your meaure.

1. rank measure.

rank = RANKX(FILTER(ALL(Table1),EOMONTH([Date],0)=EOMONTH(MAX([Date]),0)&&WEEKDAY([Date],2)<6),CALCULATE(MIN([Date])),,ASC)

2.modify your measure.

YTD = 
VAR EightBusinessday =
     MINX(FILTER(ALL(Table1),EOMONTH([Date],0)=EOMONTH(MAX('Table1'[Date]),0)&&[rank]=8),[Date])
VAR EndDate =
    IF (
        TODAY () < EightBusinessday,
        EOMONTH ( TODAY (), -2 ),
        EOMONTH ( TODAY (), -1 )
    )
RETURN
    CALCULATE (
        FactLaborBudgetHourBV[M_BudgetLaborHour],
        KEEPFILTERS ( DimDate[Date] <= EndDate )
    )

 The final output is shown below:

vyalanwumsft_0-1643093191386.png


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.

Anonymous
Not applicable

Thank you

PREVIEW
 
 
 
ValtteriN
Super User
Super User

Hi,

You can create a measure with this kind of logic:

var _date = calculate(max(calendar[business day]),all(calendar),calendar[date]=today()) return
IF(_date<8,[measure with data until Novermeber],[measure with data until december])

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

The below was the query written, Kindly let me know ho we can change as per the logic

 

YTD =

VAR EightBusinessday =

CALCULATE (

MIN ( DimDate[Date] ),

DimDate[CurrentMonthBusinessDay] = 15

)

VAR EndDate =

IF (

TODAY () < EightBusinessday,

EOMONTH( TODAY (), -2 ),

EOMONTH ( TODAY (), -1 )

)

RETURN

CALCULATE (

FactLaborBudgetHourBV[M_BudgetLaborHour],

KEEPFILTERS( DimDate[Date] <= EndDate )

)

amitchandak
Super User
Super User

@Anonymous , Assume you have two measure like

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

 

Then you can have a measure 

if(day(Today()) < 8 , [MTD Sales],[last MTD Sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.