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! Request now

Reply
Anonymous
Not applicable

Creating DAX with number of days in months

Hi all,

I need to create the following formula into DAX = accounts receivable at month end/3 months total sales/# of days in 3 months

 

So, for example, for March, it will be = March AR / Jan - Mar sales / Jan - Mar number of days

 

I am able to create the following DAX:

 

DIVIDE(
        CALCULATE(SUM('A/R'[Amount]), 'A/R'[Date] = "2022-03-01"),
            SUM(Sales[Jan]) + SUM(Sales[Feb]) + SUM(Sales[Mar]))
 
What I'm having problem with is to incorporate the number of days. 
 
I created a date table:
 
personalwafer_0-1661875107548.png

 

But having problem in creating the DAX that works 
 
Created the following but it doesn't work 

 

DIVIDE(
        CALCULATE(SUM('A/R'[Amount]), 'A/R'[Date] = "2022-03-01"),
            SUM(Sales[Jan]) + SUM(Sales[Feb]) + SUM(Sales[Mar]),
            CALCULATE((COUNT('Calendar'[MonthYearNumber] = "22 01") || COUNT('Calendar'[MonthYearNumber] = "22 02") || COUNT('Calendar'[MonthYearNumber] = "22 03"))
    ))
 
Any chance someone can point me to the right direction?
 
Thanks!!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I end up using 3 different measures. One measure (Measure1)  just to calculate the number of days, one measure (Measure2) to calculate AR/sales, and then another measure to calculate measure1/Measure2. 

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , try like

 

DIVIDE(
CALCULATE(SUM('A/R'[Amount]), 'A/R'[Date] = "2022-03-01"),
SUM(Sales[Jan]) + SUM(Sales[Feb]) + SUM(Sales[Mar]),
CALCULATE((COUNT('Calendar'[MonthYearNumber] = "22 01") + COUNT('Calendar'[MonthYearNumber] = "22 02") + COUNT('Calendar'[MonthYearNumber] = "22 03"))
))

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
Anonymous
Not applicable

@amitchandak 

 

I created a measure just to calculate the number of days and the following measure works:

 

personalwafer_0-1661906903053.png

 

However, when I tried to incorporate this measure onto the other measure, it didn't work:

 

personalwafer_1-1661906980137.png

 

Any chance you can tell me what needs to be done here?

Anonymous
Not applicable

I end up using 3 different measures. One measure (Measure1)  just to calculate the number of days, one measure (Measure2) to calculate AR/sales, and then another measure to calculate measure1/Measure2. 

Anonymous
Not applicable

@amitchandak 

 

I tried the following which does not work either:

 

personalwafer_0-1661882311254.png

 

Nor this one:

 

personalwafer_0-1661882781496.png

 

Anonymous
Not applicable

@amitchandak 

 

Received the following error message:

 

personalwafer_0-1661877543045.png

 

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.

Top Solution Authors