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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
powerbiAG
Frequent Visitor

LTM calculation using different reference dates

 

 

 

Hi All,

We have a scenario wherein a corporation has on-boarded other businesses and all the details are available in Subsidiary master  table. Sample data below...

 

 Org Id

 Name

 Integration Month

1

Business 1

Feb-21

2

Business 2

Dec-19

3

Business 3

Oct-18

 

We have Sales transaction tables historic and current (with same structure)

 

 Org Id

 Month

Value (Historic)

1

Jan-20

100

1

Feb-20

200

1

Mar-20

120

2

Sep-19

100

2

Aug-19

300

2

Nov-19

120

3

Jul-18

100

3

Apr-18

100

3

Sep-18

120

 

 Org Id

 Month

Value (Current)

1

Jan-22

100

1

Feb-22

200

1

Mar-22

120

2

Jan-22

100

2

Feb-22

300

2

Mar-22

120

3

Jan-22

100

3

Feb-22

100

3

Mar-22

120

 

Requirement is to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the master.

 

expected sample output..

 

 Org Id

LTM Value Historic

1

420 (100 + 200 + 120)

2

520 (100 + 300 + 120)

3

320 (100 + 100 + 120)

 

the sample data has been provided only for 3 months.

 

Thanks.

 

 

 

 

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

Hi @powerbiAG ,

 

If you want to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the fact table, I think LTM Value Historic for  Org Id =1 should be 200+120 instead of 100+200+120. Due to Integration Month for Org Id =1 is 2021/Feb, so last 12 month should be from 2020/Feb to 2021/Jan. So 2020/Jan is not in range. 

Try code as below to create a calculated column.

LTM Value Historic =
VAR _Last12months =
    FILTER (
        CALENDARAUTO (),
        [Date]
            <= EOMONTH ( 'Table'[Integration Month], -1 ) + 1
            && [Date]
                >= EOMONTH ( 'Table'[Integration Month], -13 ) + 1
    )
RETURN
    CALCULATE (
        SUM ( 'Sales transaction (historic)'[Value (Historic)] ),
        FILTER (
            'Sales transaction (historic)',
            'Sales transaction (historic)'[Month] IN _Last12months
        )
    )

Result is as below.

RicoZhou_0-1675332296570.png

 

Best Regards,
Rico Zhou

 

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

4 REPLIES 4
powerbiAG
Frequent Visitor

RicoZhou  .....Thank you for your help.

I was trying to create a measure (instead of a calculated column as per your provided solution) 

powerbiAG
Frequent Visitor

@v-rzhou-msft  any thoughts on the above please...

v-rzhou-msft
Community Support
Community Support

Hi @powerbiAG ,

 

If you want to calculate the last 12 months Sales Value (Historic) data (for each business) based on the "integration month" in the fact table, I think LTM Value Historic for  Org Id =1 should be 200+120 instead of 100+200+120. Due to Integration Month for Org Id =1 is 2021/Feb, so last 12 month should be from 2020/Feb to 2021/Jan. So 2020/Jan is not in range. 

Try code as below to create a calculated column.

LTM Value Historic =
VAR _Last12months =
    FILTER (
        CALENDARAUTO (),
        [Date]
            <= EOMONTH ( 'Table'[Integration Month], -1 ) + 1
            && [Date]
                >= EOMONTH ( 'Table'[Integration Month], -13 ) + 1
    )
RETURN
    CALCULATE (
        SUM ( 'Sales transaction (historic)'[Value (Historic)] ),
        FILTER (
            'Sales transaction (historic)',
            'Sales transaction (historic)'[Month] IN _Last12months
        )
    )

Result is as below.

RicoZhou_0-1675332296570.png

 

Best Regards,
Rico Zhou

 

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

 

 

Hi Rico,

Thanks for the reply.

I tried to replicate your solution, but am getting error which says "A single value for column 'Integration Month' in table 'Table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum...."

 

Am I missing something ?

PBI.png

 

Any advise would be highly appreciated.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.