0
votes

I have a table with Orders and a table with Order Status (relationship 1:many on Order Status), I'm trying to filter or Count the rows in the Order Status table less than or equal to the minimum value in the Orders table, for example the minimum value here would be 2, so I want to get only the rows "Order Created" and "Shipped" in the Order Status table.

I have tried creating the measure below with no luck:

Status = 
var minvalue = min('Orders'[Order Status #])

RETURN = 
CALCULATE(
    COUNTROWS('Order Status'), 
    'Order Status #' <= minvalue
)

Tables and Expected Result

2

2 Answers

0
votes

You can create a new table by filtering the status table based on the value on order table with filter function as following , accept the answer if helping :)

Table = FILTER('Status','Status'[Order status #]<=MIN(Orders[order status #]))

enter image description here

0
votes

If you wants to show/hide row from Status table, you can create this below Measure as flag-

show_hide_flag = 
var min_order_status = 
CALCULATE(
    MIN(Orders[Order Status #]),
    ALL(Orders)
)

RETURN 
IF(
    MIN('Status'[Order Status #]) <= min_order_status,
    1,
    0
)

Here is row wise value for the above Measure-

enter image description here

Now you can apply filter using the new flag measure and the output will be as below-

enter image description here

But, if you only wants the count of rows from table Status, you can create a Measure as below-

count_ = 
var min_order_status = 
CALCULATE(
    MIN(Orders[Order Status #]),
    ALL(Orders)
)

RETURN 
COUNTROWS(
    FILTER(
        ALL('Status'),
        'Status'[Order Status #] <= min_order_status
    )
)

And here is the output-

enter image description here