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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count if measure returns true - error with total value

Hi, 

I try to count how many documents have a final cost amount >= 500euro.
For 10 nov 2020 this should return 7.


I created a measure that returns a correct value per row (see table in screenshot).

But the total value is wrong. It says 279 (which is the count of all rows) instead of 7.

2022-01-04_17h36_12.png

I tried different measures but nothing is working....
In the above screenshoted table the VAR Test1 is applied. 

2022-01-04_17h39_41.png

 

Anyone knows how I need to modify the measure? 

Julie

1 ACCEPTED SOLUTION

Hi @Anonymous ,

In the formula, try to use the measure [Final Cost Amount] directly, but not SUM(FactControlReportsALL[Final_Cost_Amount])

Best Regards,
Community Support Team _ kalyj

View solution in original post

12 REPLIES 12
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

You can modify the measure like this:

Final Cost Amount>500euro = 
VAR _T =
    ADDCOLUMNS (
        'FactControlReportsALL',
        "Requirment", IF ( [Final_Cost_Amount] >= 500, 1, BLANK () )
    )
RETURN
    SUMX ( _T, [Requirment] )

Get the expected result.

vkalyjmsft_0-1641538164143.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hi @v-yanjiang-msft , it is still not working. 
The row values are now correct, but the total value is wrong. 
2022-01-07_09h44_05.png

Hi @Anonymous ,

Isn't "Final Cost Amount" a measure? It seems a measure in your original post.

Best Regards,
Community Support Team _ kalyj

 

 

Anonymous
Not applicable

Yes [Final Cost Amount] was a measure. 

[Final Cost Amount] = SUM(FactControlReportsALL[Final_Cost_Amount])

I wrote it out in the 'final cost amount >= 500' measure instead of refering to the 'Final Cost Amount' measure (which simply is a sum of final cost amount). This to avoid confusion 

 

 

Hi @Anonymous ,

In the formula, try to use the measure [Final Cost Amount] directly, but not SUM(FactControlReportsALL[Final_Cost_Amount])

Best Regards,
Community Support Team _ kalyj

Anonymous
Not applicable

It worked ! Thanks ! 🤗

But I don't understand what is the difference between refering to another measure (which works) and includind the calculation in the measure itself (not working)?

As in both cases it is the same calculation? Could you explain?

2022-01-07_10h24_37.png

Hi @Anonymous ,

It's my pleasure! In this formula maybe because the ADDCOLUMN function, it means create a new table in the measure, you can refer to this artical.

Reference:ADDCOLUMNS function (DAX) - DAX | Microsoft Docs

Best Regards,
Community Support Team _ kalyj

Anonymous
Not applicable

Hi @v-yanjiang-msft , This solution does not work unfortunantely. 
For precision: in my data one document number can have several rows with different articles. 
In the below table the column document_number is a distinct count.
2022-01-07_08h41_58.png

Hi @Anonymous ,

Try to modify the measure like this:

Final Cost Amount>500euro = 
VAR _T =
    ADDCOLUMNS (
        DISTINCT('FactControlReportsALL'[Document_Number]),
        "Requirment", IF ( [Final_Cost_Amount] >= 500, 1, BLANK () )
    )
RETURN
    SUMX ( _T,[Requirment] )

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

ValtteriN
Super User
Super User

Hi,

I think the problem is with your [Final cost amount] measure. I suppose it return more than 500 to all rows.

Now if you use this as your condition in test1 it will return true to all rows since the sum is greater. It seems you use a column instead of your measure in your table. To create the condition measure you can use something like:

Final cost Amount test = SELECTEDVALUE('Table'[Final_cost_amount])

I hope this helps and if it does consider accepting this as a solution and giving the post a thumbs up!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi @ValtteriN , indeed the VAR Requirement refers to a measure. Sorry forgot to precise this.

[Final Cost Amount] = SUM(FactControlReportsALL[Final_Cost_Amount])

2022-01-07_08h49_20.png

I tried to use SELECTEDVALUE. 

Created VAR Requirement2 and used this in VAR Test1. But it does not behave as expected.

One document number can have several rows in the data (different articles with the same document number). It seems that this measure returns 1 when the final cost amount is >= 500 for one article/row. It should return 1 if the final cost amount is >= 500 for the document number (so sum of final cost amount of the different rows with same document number). 
Also the total value is blank 😕

2022-01-07_08h51_48.png

smpa01
Super User
Super User

@Anonymous  is it kindly possible to provide a sample pbix?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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