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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
KV2022
Helper II
Helper II

difference between to fact table columns based on conditions involving a fact and dim table

Hi , am new to power bi. can anyone help with this?

I need to find a difference between two date columns in fact table based on a flag in the fact table and one column in dimension table. This needs to be a measure.

 

thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@KV2022 , If both dates are in Fact, use related(Dim[Date]) if date is in dimension

 

Calculate(Sumx(Table, Datediff([Date1], [Date2], day) , filter(Table,Table[Col] = "ABC"), Filter(Dim, Dim[Col] ="ABC") )

 

You can use Averagex in place of sumx 

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

View solution in original post

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @KV2022 ;

You could try to create this measure.

diff =
SUM ( 'fact'[flag] ) - SUM ( 'dimension'[column] )

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


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

 

amitchandak
Super User
Super User

@KV2022 , If both dates are in Fact, use related(Dim[Date]) if date is in dimension

 

Calculate(Sumx(Table, Datediff([Date1], [Date2], day) , filter(Table,Table[Col] = "ABC"), Filter(Dim, Dim[Col] ="ABC") )

 

You can use Averagex in place of sumx 

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

thanks.

 

But the dates are in fact table and so is the flag.  Something like this 

fact(actual end date)- fact(actual start date)  on fact(flag) = value and dim(column) = value. 

it needs to be a measure

@KV2022 , If values are coming from the slicer, you do not need even add filter code

 

Also, I suggested a measure only

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

thanks.I will try that

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.