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
shayla
Frequent Visitor

Calculate measure from a different fact table

Hi everyone, 

 

could anyone help me with the formula?

 

I have two fact tables NetSales and Lead Table. 

 

NetSales Table has Customer ID, Date, Material#, Volume columns

 

Lead Table has Customer ID, Lead Start Date (different customers could have different lead start date with same campaign ID), Campaign ID.

 

And I want to calculate the volume for Material A for customers 12 months before the leads start date.

 

I have formula below and it doesn't work.

 

LeadStartDates =
    CALCULATETABLE(
        SUMMARIZECOLUMNS(
             'Lead'[Customer ID],
             'Lead'[Campaign ID],
             'Lead'[Lead Start Date],
             RELATEDTABLE(NetSales),
             "Vol",CALCULATE(Sales[Vol],DimProduct[PRH2#]="011")
            ),
        'Lead'[Campaign ID]<>""&&LEFT('Lead'[Campaign ID],1)="0")

shayla_0-1712825143647.png

 

 

Thanks,

Shayla

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

Hi @shayla,

As per your description, I have created two tables and created relationships for them.

vkaiyuemsft_0-1712900611342.png


Create MEASURE.

 

Volume Before Lead Start =
CALCULATE(
SUM(NetSales[Volume]),
FILTER(
'NetSales'.
NetSales[Material#] = "A" &&
NetSales[Customer ID] IN VALUES('Lead'[Customer ID]) &&
DATEDIFF(NetSales[Date], RELATED('Lead'[Lead Start Date]), MONTH) <= 12 &&
DATEDIFF(NetSales[Date], RELATED('Lead'[Lead Start Date]), MONTH) > 0
)
)

 

 

vkaiyuemsft_1-1712900645198.png

If the results obtained are not what you expected. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Clara Gong

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

1 REPLY 1
v-kaiyue-msft
Community Support
Community Support

Hi @shayla,

As per your description, I have created two tables and created relationships for them.

vkaiyuemsft_0-1712900611342.png


Create MEASURE.

 

Volume Before Lead Start =
CALCULATE(
SUM(NetSales[Volume]),
FILTER(
'NetSales'.
NetSales[Material#] = "A" &&
NetSales[Customer ID] IN VALUES('Lead'[Customer ID]) &&
DATEDIFF(NetSales[Date], RELATED('Lead'[Lead Start Date]), MONTH) <= 12 &&
DATEDIFF(NetSales[Date], RELATED('Lead'[Lead Start Date]), MONTH) > 0
)
)

 

 

vkaiyuemsft_1-1712900645198.png

If the results obtained are not what you expected. Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Best Regards,

Clara Gong

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

 

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.