multiple conditions
2 TopicsCalculated column based on lookup table returns empty
I'm trying to calculate for every contract in a dataset with contracts whether or not a specific budget applies or not. This budget I need to detract from my overall figure, so I need to have it on a contract to contract basis. I have queried a simple lookup table where I have all the relevant filter columns (product, model, duration, ...) and how high the specific budget is for these conditions. I want to calculate a column with for each contract the applied budget. I'll enclose my current DAX lines for calculating this column, and it does not give me syntax errors, but the resulting column is completely empty. My main table is 'Retail+Fleet' and 'Special actions' is the small lookup table with the conditions and the [Budget action] column with the size of the specific budget. I've also included a simplified version of the two tables, where the green column indicates what I expected the resulting column to look like, but that at the moment is completely empty (not even showing null or 0). Does anyone have an idea where I'm making a mistake? SpecialAction = /* Use if lookup doesn't bring anything back - this is for easiness just set to 0 */ VAR DefaultAction = 0 /* Product Class (to filter on PL) */ VAR ProductPL = 'Retail+Fleet'[Product Class] /* New Car */ VAR NewCar = 'Retail+Fleet'[New/Used car] /* Duration */ VAR Duration = 'Retail+Fleet'[Contract duration] /* Calculation Date */ VAR CalculationDate = 'Retail+Fleet'[Calculation date] /* CMIS Brand */ VAR CMISBrand = 'Retail+Fleet'[CMIS Brand] /* Model */ VAR CarModel = 'Retail+Fleet'[Model] /** Filter all contracts to see whether they fall within the specific conditions, and check whether the creation date falls within the to and from date range. The BLANK() value ensures that for the lines where the Car Model or the Duration is not filled in, the filter option is not stopped. **/ RETURN CALCULATE(FIRSTNONBLANK('Special actions'[Budget action],1), FILTER( 'Special actions', 'Special actions'[Product Class] = ProductPL && CalculationDate >= 'Special actions'[Date From] && CalculationDate <= 'Special actions'[Date To] && 'Special actions'[VN - VO] = NewCar && ('Special actions'[Duration] <= Duration || 'Special actions'[Duration] = BLANK()) && 'Special actions'[CMIS Brand] = CMISBrand && ('Special actions'[Model] = CarModel || 'Special actions'[Model] = BLANK()) )) Lookup Table ('Special actions') Product Class CMIS Brand Model Duration Date From Date To VN - VO Budget action PL Brand 1 24 1/1/24 31/1/24 VN 800 PL Brand 1 36 1/1/24 31/1/24 VN 1000 PL Brand 1 48 1/1/24 31/1/24 VN 1000 PL Brand 1 Model 1 48 1/1/24 31/1/24 VN 1500 PL Brand 2 Model 2 48 1/1/24 31/1/24 VN 600 PL Brand 3 Model 3 48 1/1/24 31/1/24 VN 600 Main Table ('Retail+Fleet') Product Class CMIS Brand Model Contract Duration Calculation date ... New/Used car SpecialAction AC Brand 1 Model 6 36 20/12/23 ... VN CC Brand 1 Model 40 24 30/12/23 ... VN OL Brand 1 Model 1 60 3/1/24 ... VN PL Brand 2 Model 2 48 5/1/24 ... VN 600 PL Brand 3 Model 4 48 12/1/24 ... VN PL Brand 1 Model 2 60 19/1/24 ... VO PL Brand 1 Model 1 24 30/1/24 ... VN 1500 PL Brand 1 Model 3 36 2/2/24 ... VN PL Brand 2 Model 3 30 18/2/24 ... VO PL Brand 3 Model 2 72 1/3/24 ... VNSolved661Views0likes2CommentsLOOKUP VALUE BETWEEN DATES AND MULTIPLE CONDITIONS
Hello!! This may be already posted, but can't find it or related. I have 2 tables, a master table like this: KEY BND SEC START_HOUR END_HOUR REPS 8 S2 18/04/23 5:00 pm 19/04/23 2:00 am REPS 8 S1 18/04/23 6:00 am 18/04/23 5:00 pm ZATR 8 S3 18/04/23 9:00 pm 19/04/23 4:00 am ZATR 8 S1 18/04/23 8:00 am 18/04/23 7:00 pm MAKI 3 S2 18/04/23 9:00 pm 19/04/23 4:00 am QWER 2 S3 18/04/23 5:30 am 18/04/23 1:30 pm ZATR 3 S2 18/04/23 10:00 pm 19/04/23 5:00 am And values table: KEY BND HOUR ACT REPS 8 18/04/23 5:35 pm REPS 8 18/04/23 6:34 am ZATR 3 19/04/23 2:30 am This is only a sample but imagine I have hundreds of rows; many KEY and BND values, and start and end hour changes for any combination of them. This means that for REPS code I can have SEC with different Start and End hours. (SEC only have values from S1 to S3). I can even have 30 mins in hour schedule, as you can see in the last row. Master table never changes, is a master at the end, Values table shows what happened at specific time, so I need to get that SEC value. I need to add a column with the vale from column SEC to values table according to CODE and LINE columns, but that is between the Start and End HOURS. An expected result value would be: KEY BND HOUR ACT SEC REPS 8 18/04/23 5:35 pm S2 REPS 8 18/04/23 6:34 am S1 ZATR 3 19/04/23 2:30 am S2 As you can see, KEY = RESP and BND = 8, so at HOUR=18/04/23 5:35 pm some value was stored in ACT column (not important for this query). So for this HOUR, we go to the master table where for those KEY & BND values, HOUR is between START_HOUR and END_HOUR where SEC = S2, so I bring S2. And so. I hope I'd clear. Thanks in advance.1.5KViews0likes4Comments