Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
Hi All,
I need help with Dax measure. Requirement is to get total quantities from Sales table only for those locations which exists in target table and transaction date of Sales should be greater than StartDate in Target Table.
SampleTables :
Targets:
| Location | Area | Region | StartDate | Target | 
| L01 | A1 | R1 | 05/06/2023 | 100 | 
| L02 | A2 | R1 | 07/07/2023 | 150 | 
DimSite:
| SiteKey | Location | Area | Region | 
| S1 | L01 | A1 | R1 | 
| S2 | L02 | A2 | R1 | 
| S3 | L03 | A1 | R1 | 
| S4 | L04 | A3 | R2 | 
Sales :
| SiteKey | TransactionDate | Qty | 
| S1 | 01/01/2023 | 40 | 
| S1 | 06/06/2023 | 30 | 
| S1 | 07/06/2023 | 40 | 
| S2 | 05/07/2023 | 60 | 
| S2 | 10/07/2023 | 50 | 
| S3 | 10/07/2023 | 40 | 
| S4 | 12/12/2023 | 70 | 
Expected output is:
| Location | Qty | 
| L1 | 70 | 
| L2 | 50 | 
Relationship between tables are :
DimSite[Sitekey] ---> Sales[Sitekey] (one to many)
DimSite[LocationCode] <----> Target[LocationCode] (one- to-one)
DimDate[Date] -----> Sales[TransactionDate] (One-to-many)
Note :  Sales and dimSite table are being connected in DirectQueryMode as being loaded from exisisting power Bi model which cannot be changed and Target table in import mode which has target for limited locations.
I have created below measure which is giving correct output but taking ages to load on visual. 
Thanks in advance!
 
					
				
		
Hi @BI_Prachi
Please try the following:
Here's some dummy data
"Targets"
"Sales"
"DimSite"
Create a measure.
Qty = 
VAR TargetLocations = 
    CALCULATETABLE(
        VALUES(Targets[Location]),
        REMOVEFILTERS(DimSite)
    )
RETURN
    CALCULATE(
        SUM(Sales[Qty]),
        Sales[TransactionDate] > MIN(Targets[StartDate]),
        DimSite[Location] IN TargetLocations
    )
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks @Anonymous 
I tried the solution. It's working fine at location level but totals are still not matching. As transaction date is being compared with min StartDate irrespective of StartDate of respective Location.
 
					
				
				
			
		
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
 
            | User | Count | 
|---|---|
| 9 | |
| 5 | |
| 4 | |
| 3 | |
| 3 | 
| User | Count | 
|---|---|
| 23 | |
| 12 | |
| 11 | |
| 9 | |
| 8 |