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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Mohan128256
Helper III
Helper III

DAX filter the dates between two disconnected fact tables and calculate total amount

Hello All,

 

I have two fact tables in my report as InventorySnapshot and Trans_Inventory which has no any relationship between the tables.

I am filtering the dates from Inventory Snapshot table and based on the date selection, will be calculating all the inventory amount from Trans inventory table which are greater than or equal to the selected date.

 

Mohan128256_0-1695739935251.png

In above image, for selected product, date = 31-05-2023, we have three records on or after the selected date, in trans inventory table.

Below is the dax i am using for calcualte Inventory Amt.

_Inventory Amt FIN = 
VAR TotalAmt = SUM('Trans Inventory'[Inventory Amt])
VAR SelectedDate = CALCULATE(MAX('Inventory Snapshots'[Snapshot Date]),ALLSELECTED('Inventory Snapshots'[Snapshot Date]))
VAR Amt = 
CALCULATE(TotalAmt
,    FILTER(ALLSELECTED('Trans Inventory'[Physical Date]),
'Trans Inventory'[Physical Date] >= SelectedDate ) )
return 
IF(amt=0,BLANK(),amt) 

 

the expected result should be the total value of 1983, where as it is showing the 2169 as total value which is wrong.

 

Can anyone please correct my dax expression and help me out.

 

Thanks,

Mohan V.

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Mohan128256 Variables don't work that way. Variables are constants, not variable despite the name. Maybe:

_Inventory Amt FIN = 
VAR SelectedDate = MAXX(ALLSELECTED('Inventory Snapshots'[Snapshot Date]), 'Inventory Snapshots'[Snapshot Date])

VAR __Table = FILTER( FILTER(ALLSELECTED('Trans Inventory'[Physical Date]),
'Trans Inventory'[Physical Date] >= SelectedDate )

VAR Amt = SUMX( __Table, [Inventory Amt])

VAR __Result = IF( Amt = 0, BLANK(), Amt )
RETURN
  __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@Mohan128256 Variables don't work that way. Variables are constants, not variable despite the name. Maybe:

_Inventory Amt FIN = 
VAR SelectedDate = MAXX(ALLSELECTED('Inventory Snapshots'[Snapshot Date]), 'Inventory Snapshots'[Snapshot Date])

VAR __Table = FILTER( FILTER(ALLSELECTED('Trans Inventory'[Physical Date]),
'Trans Inventory'[Physical Date] >= SelectedDate )

VAR Amt = SUMX( __Table, [Inventory Amt])

VAR __Result = IF( Amt = 0, BLANK(), Amt )
RETURN
  __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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