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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AdamD123
Helper I
Helper I

Monthly Usage Calculation

Hello,

 

I have a calculation which is working for some lines but not otherS, I was hoping someone could point me the right direction as to where I have gone wrong?

 

I am trying to work out an average monthly usage per line, since January 2022. For example PP0002, we have used 511x (Qty of postings) since the beginning of 2022. This equates to an average of 18.25 (511 / 28 (completed months) = 18.25).

 

Whereas PP0001, we have used 4x (Qty of postings) since the beginning of 2022. This equates to an average of 0.14 (4 / 28 = 0.142587) but this is showing as 1.33?

Monthly Usage 1.PNGMonthly Usage 2.PNG

Any help is greatly appreciated.

 

Kind regards,

Adam

 

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

Hi @AdamD123

 

I speculate the issue can be caused by the code:

 

DATEDIFF(MIN (ItemLedgerEntries[Posting_Date]),MAX (ItemLedgerEntries[Posting_Date]),month)

 

 

Maybe you can try to output the result for just this piece of code and see if it's 28.

If not, please try this:

 

MEASURE =
VAR _CountMonth =
    CALCULATE (
        DATEDIFF (
            MIN ( ItemLedgerEntries[Posting_Date] ),
            MAX ( ItemLedgerEntries[Posting_Date] ),
            MONTH
        ),
        ALLSELECTED ( ItemLedgerEntries )
    )
RETURN
    SUM ( ItemLedgerEntries[Quantity] ) / _CountMonth

 

 

Hope it helps,

 

Best Regards

Zhengdong Xu
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

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @AdamD123

 

I speculate the issue can be caused by the code:

 

DATEDIFF(MIN (ItemLedgerEntries[Posting_Date]),MAX (ItemLedgerEntries[Posting_Date]),month)

 

 

Maybe you can try to output the result for just this piece of code and see if it's 28.

If not, please try this:

 

MEASURE =
VAR _CountMonth =
    CALCULATE (
        DATEDIFF (
            MIN ( ItemLedgerEntries[Posting_Date] ),
            MAX ( ItemLedgerEntries[Posting_Date] ),
            MONTH
        ),
        ALLSELECTED ( ItemLedgerEntries )
    )
RETURN
    SUM ( ItemLedgerEntries[Quantity] ) / _CountMonth

 

 

Hope it helps,

 

Best Regards

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

Hello @v-zhengdxu-msft ,

Thank you for your reply and help, your code seems to have worked! I can't say I understand it (my lack of Power BI knowledge) but it is certainly showing the correct figures, which I would expect to see when manually calculating.

Thank you ever so much for the help!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.