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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Cannot use "does not equal" in Filter function?

I have a calculated column that I use to calculate the weighted average for my dataset. Oringially, in my query, I filtered out data in a column that had the amount of 0. I used the following column to caclulate my weighted average:

 

Weight = 
VAR
    IDS = Data[ID Number]
RETURN
CALCULATE(SUMX(Data,Data[Days Old]*Data[Total Amount Due]),FILTER('Data',Data[ID Number]=IDS))/SUM(Data[Days Old])

Then, I realized I wanted to actually include the data in the column that had an amount of zero for some other analysis I was doing. I adjusted my query to also include this data. This data would mess up the weighted average calculation I was doing because it should not be included in the calculation. My solution was to just add another filter to the formula to filter out the zero amounts just as I did in my query originally. That is when I received the error:

 

"A function 'FILTER' has been used in a True/False expression that is usead as a table filter expression. This is not allowed"

 

How can I achieve what I am looking to do? My formula that errored out is below:

 

Weight = 
VAR
    IDS = Data[ID Number]
RETURN
CALCULATE(SUMX(Data,Data[Days Old]*Data[Total Amount Due]),FILTER('Data',Data[ID Number]=IDS),FILTER('Data',Data[Total Amount Due]<>0)/SUM(Data[Days Old]))

Thanks.

3 REPLIES 3
malagari
Responsive Resident
Responsive Resident

Your last FILTER argument is attempting to do FILTER(Data, [Total Amount Due] <> 0) and then dividing by the SUM function. What exactly are you trying to do here?  Is the division by SUM supposed to be happening to the result of the CALCULATE? If so, you need to adjust your parentheses.

 

This is what your expression is currently saying, formatted:

 

Weight = 
VAR
    IDS = Data[ID Number]
RETURN
CALCULATE(
SUMX(
Data,
Data[Days Old] * Data[Total Amount Due]
),
FILTER('Data', Data[ID Number] = IDS),
FILTER('Data', Data[Total Amount Due] <> 0) / SUM(Data[Days Old])
)

 

Did you mean to do something like this at the end?

   FILTER('Data', Data[Total Amount Due] <> 0)
) / SUM(Data[Days Old])
Dan Malagari
Consultant at Headspring
Anonymous
Not applicable

Thanks for the reply.

 

What I am trying to do is by row, multiply the Days Old column by the Total Amount Due column. Then divide this result by the sum of the entire Days Old column. 

 

There is a column ID Number that should be unique per row, so this filter I guess is included to make sure it multiples only by each row (not sure if that is necessary).

 

And then finally I also now want to filter this calculation to not include any rows where the Total Amount Due column is zero. So if the Total Amount Due column is zero for a particular row, it should not multiply Days Old by Total Amount due and it should also not include this row in the sum of Days Old column which is what I am dividing by at the end.

 

Let me know if that doesn't make sense.

 

 

@Anonymous,

 

If convenient, share us an example. Check if the following calculated column works.

Column =
DIVIDE (
    Data[Days Old] * Data[Total Amount Due],
    SUMX ( Data, Data[Days Old] * Data[Total Amount Due] )
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
March Fabric Community Update

Fabric Community Update - March 2024

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

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.