0
votes

I'm kinda new to dax and wondering if someone could help me with this:

I need a measure that count the number of rows that meets a specific criteria , and where the result of dividing each row for column A with column B falls in a specific range. Here is an example how I would have solved it in Excel:

+-----+-----+-------------------+
|  A  |  B  | Calculated column |
+-----+-----+-------------------+
| 1,4 | 1,3 | 108 %             |
| 1,1 | 1,4 | 79 %              |
| 0,8 | 1,1 | 73 %              |
|   1 | 1,3 | 77 %              |
| 1,3 | 1,4 | 93 %              |
| 1,1 |   1 | 110 %             |
| 1,3 | 1,3 | 100 %             |
| 1,5 | 0,8 | 188 %             |
| 0,9 | 1,4 | 64 %              |
| 1,1 |   1 | 110 %             |
+-----+-----+-------------------+

Result: 5

Formula in Excel:=COUNTIFS(E8:E17;">=0,9";E8:E17;"<=1,1")

I could do the same in powerpivot: Create a calculated column that divides column A with column B, and then count the number of rows in that column that falls within the specific range, but I will have quite a few ranges and would like to avoid all those extra columns if possible.

Is it possible to calculate this in one measure?

BR Johan

1

1 Answers

0
votes

Let's say your table name is "Fact".

Measure:

   Result     =
        COUNTROWS ( 
          FILTER ( 'Fact',
            VAR Ratio = DIVIDE ( 'Fact'[A], 'Fact'[B] ) 
            RETURN Ratio >= 0.9 && Ratio <= 1.1 ))

How it works: First, inside FILTER function A/B ratio is calculated and stored in a variable. Then table is filtered by the ratio within the range you need. Finally, rows of the filtered table are counted.