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
jhowe1
Helper III
Helper III

Average not in date period

What is the equivalent DAX of the following SQL? i.e. vends not in date period...

 

 

 

SELECT AVG(CountRows)
FROM pbi.FactVend AS FV
    JOIN pbi.DimAsset AS DA ON DA.KEY_Asset = FV.KEY_Asset
WHERE CAST(FV.KEY_VendDate AS Date) NOT BETWEEN DA.ExcludedFromDate AND DA.ExcludedToDate

 

 

 

Something along the lines of (can't get DAX right)

 

 

 

Average Cup Vends = 
CALCULATE(AVERAGE(Vend[CountRows]), CONVERT(Vend[KEY_VendDate], DATETIME) 
NOT IN FILTER(Asset, DATESBETWEEN(CONVERT(Vend[KEY_VendDate], DATETIME), Asset[Excluded From Date], Asset[Excluded To Date])))

 

 

 

1 ACCEPTED SOLUTION

The answer to this was simply to add the keyword

RELATED ( Asset[Excluded From Date] ),
RELATED ( Asset[Excluded To Date] ) to my fields from the non filtered table.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

Hi @jhowe1 ,

 

Please show some sample data and expected result.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

The answer to this was simply to add the keyword

RELATED ( Asset[Excluded From Date] ),
RELATED ( Asset[Excluded To Date] ) to my fields from the non filtered table.
amitchandak
Super User
Super User

@jhowe1 , Try a measure like

 

Average Cup Vends =
CALCULATE(AVERAGE(Vend[CountRows]), FILTER(Asset, not(DATESBETWEEN(CONVERT(Vend[KEY_VendDate], DATETIME), Asset[Excluded From Date], Asset[Excluded To Date]))))

Thanks but this won't work, the rows i want to filter are in 'Vend', but the dates i want to filter by are in Asset (two different tables). It also doesn't seem to like converting my KEY_VendDate into a datetime this is in format int YYYYMMDD.

 

jhowe1_0-1617024850898.png

There is a relationship between these two tables 

jhowe1_1-1617025381519.png

 

Can someone help me finish this please? I simply need to filter the vends where the venddate is not in the asset table period excluded dates Asset[Excluded From Date], Asset[Excluded To Date]... 

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.