Forum Discussion

shashanm's avatar
shashanm
Frequent Visitor
3 years ago
Solved

Power BI Dynamic filtering

I need to filter my Order table based on the Conditions table. The catch is that my conditions table can have any number of rows.

I have my tables in the below format - 

Condition SetBillTo_CodeShipper_CodeReceiver_Code
C1B1, B2  
C2 S1, S3R3
C3B3, B4S3, S4R2, R3, R4

 

Order NoBillToShipperReceiver
1B4S4R4
2B2S3R2
3B2S3R1
4B4S1R3
5B3S4R1
6B5S3R3
7B1S3R5
8B2S3R6
9B4S5R6
10B3S3R2

 

The consitions need to be applied in the following way - 

1. For each row in the conditions table - it's an AND condition between the 3 codes. 

2. Then we UNION the results of each row

 

For the above table I have, my results would be -

1. For C1 - 2, 3, 7, 8 

2. For C2 - 4, 6

3. For C3 - 10

Final results - 2, 3, 4, 6, 7, 8, 10

 

The equivalent SQL in this case would be - 

SELECT OrderNo FROM Orders WHERE

(BillTo IN (B1, B2))   OR        --C1

(Shipper IN (S1, S3) AND Receiver IN (R3)) OR     --C2

(BillTo IN (B3, B4) AND Shipper IN (S3, S4) AND Receiver IN (R2, R3, R4))   --C3

 

I need to be able to loop through the conditions table as the number of condiiton sets can change dynamically.

 

Can someone please help with the implementation in Power BI?

 

1 Reply