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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

 


@ 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!:
The Definitive Guide to Power Query (M)

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

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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