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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Previous Month calculation is not working correctly with multiple slicers

Hi All,

 

Where am I going wrong to get Previous Month workday calculation. But working for Current Month calculation.

 

Previous Month Workdays =
VAR a=SELECTEDVALUE('Date Dimension'[Month])
VAR b=SELECTEDVALUE('Date Dimension'[Year])
VAR c=SELECTEDVALUE('DIM_ORDER'[Order_Type])
VAR d=SELECTEDVALUE('DIM_PRODCATEGORY'[Prod_Cat])
VAR e=SELECTEDVALUE('DIM_CATEGORY'[Catageory])
VAR g=SELECTEDVALUE('DIM_CUSTOMER'[Customer_Name])

RETURN
CALCULATE(MEDIAN(Metric_WorkDays[WorkDay_Value]),
FILTER(ALLEXCEPT(Metric_WorkDays,Metric_WorkDays[Work_Days]),
Metric_WorkDays[Month No]=a-1 &&
Metric_WorkDays[Year]=b &&
Metric_WorkDays[Order_Type]=c &&
Metric_WorkDays[Prod_Cat]=d &&
Metric_WorkDays[Catageory]=e &&
Metric_WorkDays[Customer_Name]=g))
 
Current Month Workdays =
VAR a=SELECTEDVALUE('Metric_WorkDays'[Financial Month])
RETURN
CALCULATE(AVERAGE(Metric_WorkDays[WorkDayCount]),
      FILTER(ALLSELECTED(Metric_WorkDays),
           Metric_WorkDays[Financial Month]=a &&
           Metric_WorkDays[Year]=SELECTEDVALUE(Metric_WorkDays[Year])))
 
Thanks In Advance,
Tanushree
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @v-xuding-msft 

 

I was making it complex. I was considering all my slicers in Filter() of my code.

This simple DAX works for me.

Previous Month Workdays = CALCULATE(SUM(Fact_WorkDays_TBL[Workdays]),DATEADD('Date Dimension'[Date],-1,MONTH))
 
Thanks

View solution in original post

4 REPLIES 4
v-xuding-msft
Community Support
Community Support

Hi @Anonymous ,

Can you please share some sample data and the expected results? Then we will understand your requirement clearly.

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

Hi @Anonymous ,

Could you tell me if your problem has been solved? Welcome to share your own solution. More people will benefit from the thread.

 

Best Regards,

Xue Ding

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

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-xuding-msft 

 

I was making it complex. I was considering all my slicers in Filter() of my code.

This simple DAX works for me.

Previous Month Workdays = CALCULATE(SUM(Fact_WorkDays_TBL[Workdays]),DATEADD('Date Dimension'[Date],-1,MONTH))
 
Thanks
vanessafvg
Community Champion
Community Champion

@Anonymous  i could be wrong, think it may be how you calculate month, are you trying to go back a month, what if month 1 = 1 and going back is 12?  your calculation wont get there, you need to use time intelligence to calculate this properly.

 

what are you getting and can you demonstrate examples of what you want.  Are you able to use a date field?

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.