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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bramos88
Frequent Visitor

Calculating two values with one month difference

Hello everyone!

 

I'm having some trouble with calculating the division of two sums with one month difference between them.

 

Here's what I want to do: I have two columns, A and B.

MEASURE = SUM(B) / SUM(A) where the month of A is always a month before B

 

Example:

 

MEASURE = SUM(B - BEING MONTH = FEBRUARY) / SUM(A - BEING MONTH = JANUARY)

 

Can someone help me with that?

Thanks! 

1 ACCEPTED SOLUTION

Hi,

 

This data is not well structured.  Using the Query Editor, we should right click on the Date column and the right column and then unpivot the other columns to convert your dataset into a 4 column one.  Once that is done, one can easily use the Date/Time Intelligence functions to get the growth over the previous month/year by writing simple measures.


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

View solution in original post

6 REPLIES 6
bramos88
Frequent Visitor

That's the idea of the calculation:

 


Test.png

Hi,

 

This data is not well structured.  Using the Query Editor, we should right click on the Date column and the right column and then unpivot the other columns to convert your dataset into a 4 column one.  Once that is done, one can easily use the Date/Time Intelligence functions to get the growth over the previous month/year by writing simple measures.


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

Hi @bramos88,

 

Please new a calculated column with below DAX:

SumB/SumA = 
IF (
    'Table 1'[DATE].[MonthNo] < 12,
    CALCULATE (
        SUM ( 'Table 1'[B] ),
        FILTER (
            ALLEXCEPT ( 'Table 1', 'Table 1'[DATE].[Year], 'Table 1'[DATE].[Month] ),
            'Table 1'[DATE].[MonthNo]
                = EARLIER ( 'Table 1'[DATE].[MonthNo] ) + 1
                && 'Table 1'[DATE].[Year] = EARLIER ( 'Table 1'[DATE].[Year] )
        )
    ),
    CALCULATE (
        SUM ( 'Table 1'[B] ),
        FILTER (
            ALLEXCEPT ( 'Table 1', 'Table 1'[DATE].[Year], 'Table 1'[DATE].[Month] ),
            'Table 1'[DATE].[MonthNo]
                = 1 + 1
                && 'Table 1'[DATE].[Year]
                    = EARLIER ( 'Table 1'[DATE].[Year] ) + 1
        )
    )
)
    / CALCULATE (
        SUM ( 'Table 1'[A] ),
        ALLEXCEPT ( 'Table 1', 'Table 1'[DATE].[Year], 'Table 1'[DATE].[Month] )
    )

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @v-yulgu-msft

 

I tried to use that solution but I'm getting some trouble with these parts:

IF (
    'Table 1'[DATE].[MonthNo] < 12,
Consulta1[DATA_SALDO].[MonthNo] = EARLIER ( Consulta1[DATA_SALDO].[MonthNo] ) + 1

I'm getting the error that is not possible to determine one single value for "year".

 

Do you know something about it?

 

Thanks!

 

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @bramos88,

 

Please provide sample data to illustrate your desired output. If possible, post an image which shows your expected result.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

 

If columns A and B contain Months or even dates, then how can you add them?  Share some data and show the expected result.


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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.